1 | function QRBitBuffer() {
|
2 | this.buffer = new Array();
|
3 | this.length = 0;
|
4 | }
|
5 |
|
6 | QRBitBuffer.prototype = {
|
7 |
|
8 | get : function(index) {
|
9 | var bufIndex = Math.floor(index / 8);
|
10 | return ( (this.buffer[bufIndex] >>> (7 - index % 8) ) & 1) == 1;
|
11 | },
|
12 |
|
13 | put : function(num, length) {
|
14 | for (var i = 0; i < length; i++) {
|
15 | this.putBit( ( (num >>> (length - i - 1) ) & 1) == 1);
|
16 | }
|
17 | },
|
18 |
|
19 | getLengthInBits : function() {
|
20 | return this.length;
|
21 | },
|
22 |
|
23 | putBit : function(bit) {
|
24 |
|
25 | var bufIndex = Math.floor(this.length / 8);
|
26 | if (this.buffer.length <= bufIndex) {
|
27 | this.buffer.push(0);
|
28 | }
|
29 |
|
30 | if (bit) {
|
31 | this.buffer[bufIndex] |= (0x80 >>> (this.length % 8) );
|
32 | }
|
33 |
|
34 | this.length++;
|
35 | }
|
36 | };
|
37 |
|
38 | module.exports = QRBitBuffer;
|