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

Get index of first set bit from LSB. 📦 😺 🏃 📼 🌔 📜 📰 📘

Alternatives: scan, scanReverse.


bit.scan(x);
// x: an int32
const bit = require("extra-bit");

bit.scan(7);
// 0 (111 ⇒ 0)

bit.scan(12);
// 2 (1100 ⇒ 2)

bit.scan(64);
// 6 (1000000 ⇒ 6)


References

Clone this wiki locally