Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@chainsafe/bit-utils

Package Overview
Dependencies
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chainsafe/bit-utils

bitlist and bitvector utilities

  • 0.1.6
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
42
increased by23.53%
Maintainers
3
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 26 Oct 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc