0.0.0 • Published 12 months ago

@8kb/bit.io v0.0.0

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
12 months ago

bit.io

bit.io is a js/ts library for reading individual bits from an ArrayBuffer.

Install

npm install @8kb/bit.io

Usage

read bit

import { read_bit } from '@8kb/bit.io'

const array_buffer = new ArrayBuffer(2)
new Uint8Array(array_buffer).set([4], 1) // 4 = 0b00000100

const read_bit_by_index = read_bit(array_buffer)
console.log(read_bit_by_index(13)) // 1
console.log(read_bit_by_index(15)) // 0
console.log(read_bit_by_index(-1)) // 'out of range'
console.log(read_bit_by_index(0.1)) // 'invalid index'

read bits

import { read_bits } from '@8kb/bit.io'

const array_buffer = new ArrayBuffer(2)
new Uint8Array(array_buffer).set([4], 1) // 4 = 0b00000100

console.log(read_bits(array_buffer))
// [
//   0,0,0,0,
//   0,0,0,0,
//   0,0,0,0,
//   0,1,0,0,
// ]
0.0.0

12 months ago