-
Notifications
You must be signed in to change notification settings - Fork 3
kig/bitview.js
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
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)