If X is a binary number which is power of 2, then the value of X & (X – 1) is :
2017
If X is a binary number which is power of 2, then the value of X & (X – 1) is :
- A.
11….11
- B.
00…..00
- C.
100…..0
- D.
000……1
Attempted by 841 students.
Show answer & explanation
Correct answer: B
Answer: all zeros (00…..00)
Explanation: For a number that is a power of two, the binary representation has exactly one '1' and the remaining bits are '0'.
Step 1: Represent X as 100…0 (one '1' followed by zeros).
Step 2: Compute X - 1. This flips the single '1' to '0' and makes all lower bits '1', giving 011…1.
Step 3: Perform the bitwise AND: 100…0 & 011…1 = 000…0. The only set bit in X is cleared, so the result is zero.
Example: X = 8 (1000), X - 1 = 7 (0111), and 1000 & 0111 = 0000.
A video solution is available for this question — log in and enroll to watch it.