Skip to content

kig/bitview.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

bitview.js
----------
Manipulate bits in ArrayBuffers.
Works like a DataView but indexes in bits.
Also encodes and decodes 6-bit ints and 12-bit ints.

var u8 = new Uint8Array(3);
var bv = new BitView(u8.buffer);

bv.setBit(5, 1);
bv.setBit(6, 1);
bv.setBit(7, 1);

console.log(u8[0] == 7);

bv.setBit(6, 0);

console.log(u8[0] == 5);

for (var i=0; i<18; i++) {
  for (var j=-32; j<32; j++) {
    bv.setInt6(i, j);
    if (bv.getInt6(i) != j) {
      console.log('failed at', i, j);
    }
  }
}

About

BitView does per-bit access to ArrayBuffers (like DataView for bits)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published