Javascript binary file reading

前端 未结 3 1715
温柔的废话
温柔的废话 2021-01-14 22:56

From here:

_shl: function (a, b){
        for (++b; --b; a = ((a %= 0x7fffffff + 1) & 0x40000000) == 0x40000000 ? a * 2 : (a - 0x40000000) * 2 + 0x7fffff         


        
3条回答
  •  深忆病人
    2021-01-14 23:32

    • _readByte(i, size): size is the buffer length in byte, i is the reversed index (index from the end of the buffer, not from the start) of the byte which you want to read.
    • _readBits(start, length, size): size is the buffer length in byte, length is the number of bits which you want to read, start is the the index of the first bit which you want to read.
    • _shl(a, b): convert read byte a to actual value based on its index b.

    Because _readByte use reversed index, so lastByte less than curByte.

    offsetLeft and offsetRight are used to remove unrelated bits (bits not in read range) from lastByte and curByte respectively.

提交回复
热议问题