npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

uupaa.bit.js

v0.8.1

Published

Bit operation

Downloads

69

Readme

Bit.js Build Status

npm

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.n(0x000000ff, 0b00000000000000000000000011111100) // -> 0x3f,
Bit.n(0x000000ff, 0b00000000000000000000000011000000) // -> 0x03,

// bit split by bit-pattern
Bit.split32(0xffff1234, [16,4,4,4,4])  // -> [0xffff, 0x1, 0x2, 0x3, 0x4]
                                       //         16    4    4    4    4 bits

Bit.split24(0xff1234, [16,4,4]) // -> [0xff, 0x1, 0x2, 0x3, 0x4]
Bit.split16(0x1234,   [8,8])    // -> [0x12, 0x34]
Bit.split8(0xfe,      [2,2,4])  // -> [0x3, 0x3, 0xe]

// With ES6 Destructuring Assignment
var [a, b, c] = Bit.split32(0x00001234, [16, 8, 8]);
// -> a = 0x12, b = 0x3, c = 0x4

// population count (counting 1 bits)
Bit.popcnt(0x6) // -> 2

// count the number of contiguous 1 bits from Left-side or Right-side
Bit.cnl(0b11001110) // -> 2
Bit.cnr(0b11001110) // -> 3

// Number(Count) of Leading Zero
Bit.nlz(0x6)    // -> 29
Bit.clz(0x6)    // -> 29 (this function is an alias of Bit.nlz)

// Number(Count) of Training Zero
Bit.ntz(0x6)    // -> 1
Bit.ctz(0x6)    // -> 1 (this function is an alias of Bit.ntz)

// binary dump
Bit.dump(0x12345678, [4,4,8,4,4,8]);
// -> "0001, 0010, 00110100, 0101, 0110, 01111000"

// verbose dump
Bit.dump(0x12345678, bitPattern, true);
// -> "00010010001101000101011001111000(0x12345678), 0001(1,0x1), 0010(2,0x2), 00110100(52,0x34), 0101(5,0x5), 0110(6,0x6), 01111000(120,0x78)"

// get IEEE754 expression
var doublePrecision = true;
var u32array = Bit.IEEE754(0.15625, doublePrecision);
Bit.dump(u32array[0], [1,11,20]) + Bit.dump(u32array[1], [32])
// -> "0, 01111111100, 0100000000000000000000000000000000000000000000000000"


// BitView
var bitView = new BitView(new Uint8Array([0, 1, 2, 3, 0xFF, 0xFE, 0xFD, 0xFC]));

                    // read 32 bit
bitView.u32         // -> 0x00010203

                    // read 24 bit
bitView.u24         // -> 0xFFFEFD

                    // read 1 bit
bitView.u1          // -> 0x1  `11111100` (0xFC)
                    //          ~

                    // read 2 bit
bitView.u2          // -> 0x3  `11111100` (0xFC)
                    //           ~~

                    // read 5 bit
bitView.u5          // -> 0x1C `11111100` (0xFC)
                    //             ~~~~~

</script>

WebWorkers

importScripts("<module-dir>lib/WebModule.js");
importScripts("<module-dir>lib/Bit.js");
importScripts("<module-dir>lib/BitView.js");

...

Node.js

require("<module-dir>lib/WebModule.js");
require("<module-dir>lib/Bit.js");
require("<module-dir>lib/BitView.js");

...