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
Check if a number is a power of two in O(1) with n > 0 && n & (n−1) == 0. Powers of two have exactly one set bit.
Why does n & (n−1) == 0 imply n is a power of two?