Skip to content
Subhajit Sahu edited this page Feb 2, 2021 · 15 revisions

Sets a bit. 🏃 📼 📦 🌔 📒

Alternatives: set, setAs.
Similar: get, set, toggle.

bit.set(x, i, [f]);
// x: an int32
// i: bit index
// f: bit value (1)
const bit = require('extra-bit');

bit.set(6, 0, 1);
// 7 (110,0,1 => 111)

bit.set(6, 2, 1);
// 6 (110,2,1 => 110)

bit.set(6, 2, 0);
// 2 (110,2,0 => 010)

references

Clone this wiki locally