Any power of 2 minus 1 is all ones: (2 N – 1 = 111….b)
2 = 2^1. 2-1 = 1 (1b)
4 = 2^2. 4-1 = 3 (11b)
8 = 2^3. 8-1 = 7 (111b)
Take 8 for example. 1000 & 0111 = 0000
So that expression tests if a number is NOT a power of 2.
More Related Contents:
- Explain this snippet which finds the maximum of two integers without using if-else or any other comparison operator?
- Compute fast log base 2 ceiling
- Not able to calculate in C.How do you calculate in C?
- Sum of the all the numbers between a and b [closed]
- What’s the difference between “mod” and “remainder”?
- Efficient Algorithm for Bit Reversal (from MSB->LSB to LSB->MSB) in C
- Arithmetic bit-shift on a signed integer
- What is Bit Masking?
- Find most significant bit (left-most) that is set in a bit array
- Rounding integer division (instead of truncating)
- Fast computing of log2 for 64-bit integers
- Extracting bits with a single multiplication
- Power by squaring for negative exponents
- “undefined reference to `pow'” even with math.h and the library link -lm [duplicate]
- Using M_PI with C89 standard
- Are floating point operations in C associative?
- Gaussian elimination without result for acceleration
- Bitshift and integer promotion?
- Bit twiddling: which bit is set?
- Why does gdb evaluate sqrt(3) to 0?
- Implementing Logical Right Shift in C
- To the power of in C? [duplicate]
- sin, cos, tan and rounding error
- How do I get bit-by-bit data from an integer value in C?
- Algorithm to generate bit mask
- Decimal to Binary
- Evaluate Mathematical Function from String [closed]
- Conditional tests in primality by trial division
- How sqrt() of GCC works after compiled? Which method of root is used? Newton-Raphson?
- What is bit masking?