DSAverse
Bit Manipulation
Loading Bit Manipulation...
Binary Register
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
bit 15bit 0
Initializing Sorting Algorithms...
Sorting
Trees
Graphs
Preparing interactive visualizations...
Bit Manipulation
Loading Bit Manipulation...
Binary Register
Brian Kernighan's algorithm counts 1-bits in O(set bits) by repeatedly clearing the lowest set bit with n & (n−1).
An interactive step-by-step visualization for Count Set Bits is currently being built. You will be able to watch each n & (n−1) operation clear the lowest set bit in the binary register.
Back to Bit Manipulation