@chainsafe/bit-utils
TypeScript icon, indicating that this package has built-in type declarations

0.1.6 • Public • Published

bit-utils

Build Status

Bitlist/Bitvector Utilities

Install

npm install @chainsafe/bit-utils

Examples

BitList

import {BitList} from "@chainsafe/bit-utils";

// A BitList is created from a Uint8Array bitfield and a length of bits
const list: BitList = BitList.fromBitfield(Buffer.from([3]), 3);
// Or a BitList can be deserialized from a Uint8Array bitfield with a padding bit marking the length
const list2: BitList = BitList.deserialize(Buffer.from([11]));

// get length of bits
const _bitLength = list.bitLength;
// set bit
list.setBit(0, true);
// get bit
list.getBit(0) === true;
// serialize bitlist (without padding bit)
const output: Uint8Array = list.toBitfield();
// serialize bitlist (with padding bit)
const output2: Uint8Array = list.serialize();

BitVector

import {BitVector} from "@chainsafe/bit-utils";

// A BitVector is created from a Uint8Array bitfield and a length of bits
const vector: BitVector = BitVector.fromBitfield(Buffer.from([3]), 3);

// get length of bits
const _bitLength = vector.bitLength;
// set bit
vector.setBit(0, true);
// get bit
vector.getBit(0) === true
// serialize bitvector (loses length information)
const output: Uint8Array = vector.toBitfield();

API

See our autogenerated API docs

License

Apache 2.0

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.620latest

Version History

VersionDownloads (Last 7 Days)Published
0.1.620
0.1.51
0.1.459
0.1.362
0.1.22
0.1.10
0.1.01

Package Sidebar

Install

npm i @chainsafe/bit-utils

Weekly Downloads

145

Version

0.1.6

License

Apache-2.0

Unpacked Size

40.5 kB

Total Files

18

Last publish

Collaborators

  • gregthegreek
  • sadiq1971
  • beroburny
  • morrigan88
  • alexey_krasnoperov
  • irubido
  • wemeetagain
  • mpetrunic