

[!NOTE]
This is one of 201 standalone projects, maintained as part
of the @thi.ng/umbrella monorepo
and anti-framework.
🚀 Please help me to work full-time on these projects by sponsoring me on
GitHub. Thank you! ❤️
About
1D / 2D bit field implementations.
All implementations are backed by typed arrays. Due to Uint32Array
backing the width is always rounded to a multiple of 32.
Status
STABLE - used in production
Search or submit any issues for this package
Related packages
- @thi.ng/adjacency - Sparse & bitwise adjacency matrices, lists and selected traversal algorithms for directed & undirected graphs
Installation
yarn add @thi.ng/bitfield
ESM import:
import * as bf from "@thi.ng/bitfield";
Browser ESM import:
<script type="module" src="https://esm.run/@thi.ng/bitfield"></script>
JSDelivr documentation
For Node.js REPL:
const bf = await import("@thi.ng/bitfield");
Package sizes (brotli'd, pre-treeshake): ESM: 1.46 KB
Dependencies
Note: @thi.ng/api is in most cases a type-only import (not used at runtime)
Usage examples
One project in this repo's
/examples
directory is using this package:
Screenshot | Description | Live demo | Source |
---|
 | Responsive image gallery with tag-based Jaccard similarity ranking | Demo | Source |
API
Generated API docs
import { BitField, BitMatrix } from "@thi.ng/bitfield";
const field = new BitField(16);
field.setAt(0);
field.setAt(31, true);
field.at(0)
field.at(1)
field.toString();
field.resize(64)
const mat = new BitMatrix(8, 32);
for(let i = 0; i < 8; i++) mat.setAt(i, i);
mat.at(7, 7);
mat.toString();
Authors
If this project contributes to an academic publication, please cite it as:
@misc{thing-bitfield,
title = "@thi.ng/bitfield",
author = "Karsten Schmidt",
note = "https://thi.ng/bitfield",
year = 2016
}
License
© 2016 - 2025 Karsten Schmidt // Apache License 2.0