1 function BitBuffer () {
6 BitBuffer.prototype = {
8 get: function (index) {
9 var bufIndex = Math.floor(index / 8)
10 return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1
13 put: function (num, length) {
14 for (var i = 0; i < length; i++) {
15 this.putBit(((num >>> (length - i - 1)) & 1) === 1)
19 getLengthInBits: function () {
23 putBit: function (bit) {
24 var bufIndex = Math.floor(this.length / 8)
25 if (this.buffer.length <= bufIndex) {
30 this.buffer[bufIndex] |= (0x80 >>> (this.length % 8))
37 module.exports = BitBuffer