Skip to content
Subhajit Sahu edited this page Jan 24, 2021 · 7 revisions

Get index of first set bit from LSB. 📰 📘

Alternatives: scan, scanReverse.


Bit.scan(x);
// x: an int or long
import io.github.javaf.*;

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

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

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


References

Clone this wiki locally