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

ml-bit-array

v1.0.0

Published

Bit-array operations in JavaScript

Downloads

491

Readme

bit-array

NPM version build status npm download

Bit-array operations in JavaScript.

Installation

npm install ml-bit-array

Methods

All exported methods are static and do not change the original array unless indicated otherwise.
Numbers in array arguments are treated as 32-bit signed integers.
The library is designed with speed in mind so argument type and length are not checked.

count(arr)

Computes the amount of 1s in the array. This is also known as Hamming weight.

and(arr1, arr2)

Computes the logical AND operation and returns the result in a new array.

or(arr1, arr2)

Computes the logical OR operation and returns the result in a new array.

xor(arr1, arr2)

Computes the logical XOR operation and returns the result in a new array.

not(arr)

Computes the logical NOT operation and returns the result in a new array.

getBit(arr, n)

Returns true if the bit at position n is 1, false if it is 0.

Imagine that you have an array of 4-bit numbers like this ['0001', '1010'], the 0th position will be 0 because it is the most significant bit of the 0th element of the array, and the 4th position will be 1, because will be the most significant bit in the 1st element of the array (remember that the true number of bits for a number in this case is 32).

setBit(arr, n, val)

Sets the bit at position n to 1 if val is a truthy value, otherwise sets it to 0.

toBinaryString(arr)

Converts an array of numbers to a string representation of the bits, so toBinaryString([1]) will return '00000000000000000000000000000001'.
The length of the string will be arr.length * 32.

parseBinaryString(str)

Converts a string representation of bits to an array, so parseBinaryString('00000000000000000000000000000010') will return [2].
This is the exact inverse of toBinaryString.

toHexString(arr)

Converts an array of numbers to a hexadecimal representation of the bits, so toHexString([-1]) will return 'ffffffff'.
The length of the string will be arr.length * 8.

parseHexString(str)

Converts a hexadecimal representation of bits to an array, so parseHexString('00000010ffff0000') will return [16, -65536].
This is the exact inverse of toHexString.

toDebug(arr)

Returns a human-readable string from the array in the format:

0000: 0000 1000 1111 1000 0011 1101 1111 0001
0020: 0000 1000 1111 1000 0011 1101 1111 0001
0040: 0000 1000 1111 1000 0011 1101 1111 0001

Authors

License

MIT