_shl: function (a, b){
for (++b; --b; a = ((a %= 0x7fffffff + 1) & 0x40000000) == 0x40000000 ? a * 2 : (a - 0x40000000) * 2 + 0x7fffffff + 1);
return a;
},
_readByte: function (i, size) {
return this._buffer.charCodeAt(this._pos + size - i - 1) & 0xff;
},
_readBits: function (start, length, size) {
var offsetLeft = (start + length) % 8;
var offsetRight = start % 8;
var curByte = size - (start >> 3) - 1;
var lastByte = size + (-(start + length) >> 3);
var diff = curByte - lastByte;
var sum = (this._readByte(curByte, size) >> offsetRight) & ((1 << (diff ? 8 - offsetRight : length)) - 1);
if (diff && offsetLeft) {
sum += (this._readByte(lastByte++, size) & ((1 << offsetLeft) - 1)) << (diff-- << 3) - offsetRight;
}
while (diff) {
sum += this._shl(this._readByte(lastByte++, size), (diff-- << 3) - offsetRight);
}
return sum;
},
此代码的二进制文件的阅读。不幸的是,这个代码没有记录。 我想了解它是如何工作的。 (特别是_readBits和_shl方法) 在_readBits什么是offign的?也curByte和lastByte: 我认为这样的方式:
_readBits(0,16,2)curByte成为1. lastByte成为0.为什么lastByte小于curByte?或者我犯了一个错误?哪里?请帮忙!
@ Bakudan-ханювиги这并不奇怪,注意'++ b'只执行一次。 – ExpExc
我更喜欢binaryAjax.js - http://www.nihilogic.dk/labs/binaryajax/binaryajax.js - 你可以在它的网站上找到一些帮助。 – Luc125