zhangwei
2024-08-14 9d8994790fe403935ed46ad478f83ae110bb7a01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// 本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID:16  3,营业执照号:91 5 10  131    33     2 0 06 193 K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。
function QRBitBuffer() {
    this.buffer = new Array();
    this.length = 0;
}
 
QRBitBuffer.prototype = {
 
    get : function(index) {
        var bufIndex = Math.floor(index / 8);
        return ( (this.buffer[bufIndex] >>> (7 - index % 8) ) & 1) == 1;
    },
 
    put : function(num, length) {
        for (var i = 0; i < length; i++) {
            this.putBit( ( (num >>> (length - i - 1) ) & 1) == 1);
        }
    },
 
    getLengthInBits : function() {
        return this.length;
    },
 
    putBit : function(bit) {
 
        var bufIndex = Math.floor(this.length / 8);
        if (this.buffer.length <= bufIndex) {
            this.buffer.push(0);
        }
 
        if (bit) {
            this.buffer[bufIndex] |= (0x80 >>> (this.length % 8) );
        }
 
        this.length++;
    }
};
 
export default QRBitBuffer;