Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
bit-array
Advanced tools
Readme
Please use BitSet.js
This library contains a JavaScript implementation of bit arrays. The library supports:
The bit array is sparse. The following example shows how to set and get individual bits within the array:
a = new BitArray(32);
a.set(0, true);
a.set(31, true);
a.toString(); // "10000000000000000000000000000001"
a.get(1); // false
a.get(31); // true
Note that the array internally uses 32 bit integers (actually, JavaScript's number type is 64 bit, but only 32 bits can be addressed using bitwise operations,) so going beyond the given length throws an error:
a.set(32, true); // throws an index of range exception
Even though bit arrays are not that useful in JavaScript, there is one place where they excel; encoding large boolean sets for transfer between the browser and server. A JSON representation of a bit array is much smaller than an actual boolean array.
The BitArray module has two constructors:
<dt>BitArray(size, hex)</dt>
<dd>Creates a new bit array with the given size and using the hex string as value</dd>
The following instance methods are supported:
<dt>set(index, boolean)</dt>
<dd>Sets the bit at index to a value (boolean.)</dd>
<dt>get(index)</dt>
<dd>Returns the value of the bit at index (boolean.)</dd>
<dt>toggle(index)</dt>
<dd>Toggles the bit at index. If the bit is on, it is turned off. Likewise, if the bit is off it is turned on.</dd>
<dt>reset()</dt>
<dd>Resets the BitArray so that it is empty and can be re-used.</dd>
<dt>copy()</dt>
<dd>Returns a copy of this BitArray.</dd>
<dt>equals(other)</dt>
<dd>Returns true if this BitArray equals another. Two BitArrays are considered equal if both have the same length and bit pattern.</dd>
<dt>toJSON()</dt>
<dd>Returns the JSON representation of this BitArray.</dd>
<dt>toString()</dt>
<dd>Returns a string representation of the BitArray with bits in logical order.</dd>
<dt>toHexString()</dt>
<dd>Returns a hex representation of the BitArray.</dd>
<dt>toArray()</dt>
<dd>Convert the BitArray to an Array of boolean values.</dd>
<dt>count()</dt>
<dd>Returns the total number of bits set to 1 in this BitArray.</dd>
<dt>not()</dt>
<dd>Inverts this BitArray.</dd>
<dt>or(other)</dt>
<dd>Bitwise OR on the values of this BitArray using BitArray `other`.</dd>
<dt>and(other)</dt>
<dd>Bitwise AND on the values of this BitArray using BitArray `other`.</dd>
<dt>xor(other)</dt>
<dd>Bitwise XOR on the values of this BitArray using BitArray `other`.</dd>
You can install the bit array module using npm:
> npm install bit-array
Alternatively you could just include bit-array.js in your project.
Licensed under the revised BSD License. Copyright 2010-2012 Bram Stein. All rights reserved.
https://github.com/foglcz/bit-array - PHP port by Pavel Ptacek
FAQs
JavaScript implementation of bit arrays
The npm package bit-array receives a total of 508 weekly downloads. As such, bit-array popularity was classified as not popular.
We found that bit-array demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.