# read-bits

> Read Bits (1s and 0s) from Buffers, Array Buffers, Data Views, and Uint8Array with One Universal Function

Latest version **0.1.0** (published 2020-11-11) · CC0-1.0 license · 0 weekly downloads

## Install

```sh
npm install read-bits
pnpm add read-bits
yarn add read-bits
bun add read-bits
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2020-11-11 |
| First published | 2020-11-11 |
| Weekly downloads | 0 |
| License | CC0-1.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Daniel J. Dufour |
| Maintainers | danieljdufour |
| Keywords | array, arraybuffer, buffer, bits, bytes |

## Links

- npm: https://www.npmjs.com/package/read-bits
- Repository: https://github.com/DanielJDufour/read-bits
- Homepage: https://github.com/DanielJDufour/read-bits#readme
- Issues: https://github.com/DanielJDufour/read-bits/issues
- npm.io page: https://npm.io/package/read-bits

## Dependencies (1)

- [get-byte](https://npm.io/package/get-byte.md) 0.0.0

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads
- [datasets-fi-postalcodes](https://npm.io/package/datasets-fi-postalcodes.md) — 1.1K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2020-11-11
- 0.0.1 — 2020-11-11

## README

# read-bits
Read Bits (1s and 0s) from Buffers, Array Buffers, Data Views, and Uint8Array with One Universal Function

# install
```bash
npm install -S read-bits
```

# usage
The readBits function has the following parameters:
- data: a Buffer, ArrayBuffer, DataView or Uint8Array
- start: the zero-based index of the first bit to read
- end: the zero-based index of the last bit to read

```js
const readBits = require("read-bits");

// the zero-based index of the last bit to read
const start = 0;

// the zero-based index of the last bit to read
const end = 5;

// you will read 6 bits, from the first (index 0) to the 6th (index 5)

const { bits } = readBits({ data: buffer, start, end });
// bits are "011011"

const { bits } = readBits({ data: arrayBuffer, start, end });
// bits are "011011"

const { bits } = readBits({ data: dataView, start, end });
// bits are "011011"

const { bits } = readBits({ data: uint8Array, start, end });
// bits are "011011"
```

You can also specify a length or number of bits to read
```js
const { bits } = readBits({ data: buffer, start: 0, length: 6 });
// bits are "011011"
```

---
_Source: https://npm.io/package/read-bits · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
