Bit.js
Bit.js is a JavaScript library that supports the analysis of binary data. It aggregates the low-level bit manipulation functions.
This module made of WebModule.
Documentation
Browser, NW.js and Electron
<script src="<module-dir>/lib/WebModule.js"></script><script src="<module-dir>/lib/Bit.js"></script><script src="<module-dir>/lib/BitView.js"></script><script> // get contiguous n bits (bit shift and mask).Bit // -> 0x3f,Bit // -> 0x03, // bit split by bit-patternBit // -> [0xffff, 0x1, 0x2, 0x3, 0x4] // 16 4 4 4 4 bits Bit // -> [0xff, 0x1, 0x2, 0x3, 0x4]Bit // -> [0x12, 0x34]Bit // -> [0x3, 0x3, 0xe] // With ES6 Destructuring Assignmentvar a b c = Bit;// -> a = 0x12, b = 0x3, c = 0x4 // population count (counting 1 bits)Bit // -> 2 // count the number of contiguous 1 bits from Left-side or Right-sideBit // -> 2Bit // -> 3 // Number(Count) of Leading ZeroBit // -> 29Bit // -> 29 (this function is an alias of Bit.nlz) // Number(Count) of Training ZeroBit // -> 1Bit // -> 1 (this function is an alias of Bit.ntz) // binary dumpBit;// -> "0001, 0010, 00110100, 0101, 0110, 01111000" // verbose dumpBit;// -> "00010010001101000101011001111000(0x12345678), 0001(1,0x1), 0010(2,0x2), 00110100(52,0x34), 0101(5,0x5), 0110(6,0x6), 01111000(120,0x78)" // get IEEE754 expressionvar doublePrecision = true;var u32array = Bit;Bit + Bit// -> "0, 01111111100, 0100000000000000000000000000000000000000000000000000" // BitViewvar bitView = 0 1 2 3 0xFF 0xFE 0xFD 0xFC; // read 32 bitbitViewu32 // -> 0x00010203 // read 24 bitbitViewu24 // -> 0xFFFEFD // read 1 bitbitViewu1 // -> 0x1 `11111100` (0xFC) // ~ // read 2 bitbitViewu2 // -> 0x3 `11111100` (0xFC) // ~~ // read 5 bitbitViewu5 // -> 0x1C `11111100` (0xFC) // ~~~~~ </script>
WebWorkers
;;; ...
Node.js
;;; ...