New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@zekfad/bitbyte

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zekfad/bitbyte

Flexible Byte Structure for JavaScript.

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

BitByte

npm versionnode versionBuild status - Linux/OSXBuild status - WindowsLGTM GradeCodecov

Flexible byte representation for JavaScript.

Install

Install via npm:

npm install --save @zekfad/bitbyte

Install via yarn:

yarn add @zekfad/bitbyte

Usage

Example

const BitByte = require('@zekfad/bitbyte');

const myByte = new BitByte(200);

console.log(myByte.toString()); // 11001000
console.log([...myByte]); // [ 1, 1, 0, 0, 1, 0, 0, 0 ]
console.log(myByte[1], myByte[2]); // 1 0

myByte[1] = 0;
myByte[2] = 1;

console.log(myByte.toString()); // 10101000
console.log(0 + myByte); // 168

Create byte

From unsigned byte integer

const myByte = new BitByte(200);

console.log(myByte.toString()); // 11001000

From bits array

const myByte = new BitByte([ 1, 1, 0, 0, 1, 0, 0, 0]);

console.log(myByte.toString()); // 11001000

You can also pass in Booleans:

const myByte = new BitByte([ true, true, false, false, true, false, false, false]);

console.log(myByte.toString()); // 11001000

Iterator

const myByte = new BitByte(200);

console.log([...myByte]); // [ 1, 1, 0, 0, 1, 0, 0, 0 ]

Array-like access

const myByte = new BitByte(200);

// get
console.log(myByte[1], myByte[2]); // 1 0

// set
myByte[1] = 0;
myByte[2] = 1;

Treat as a number

const myByte = new BitByte(200);

console.log(myByte == 200); // true
console.log(myByte + 0); // 200
console.log(new Number(myByte)); // [Number: 200]

String with bits

const myByte = new BitByte(200);

console.log(new String(myByte)); // [String: '11001000']
console.log(myByte.toString()); // '11001000'

Methods

For those who want to use function calls.

assign(bits, offset)

Assigns array of bits to an instance.

getBit(offset)

Returns a bit from requested offset in range from 0 to 7.

setBit(offset, bit)

Sets a bit on requested offset in range from 0 to 7.

bit must be Number (0 or 1) or Boolean.

getByte()

Returns byte as an unsigned byte integer.

getChar()

Returns character from a byte.

Keywords

bit

FAQs

Package last updated on 11 Jun 2021

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