Bird
Raised Fist0

Given the output of the bitmask check (n & 0x55555555) == 0 is false, and (n & (n - 1)) == 0 is true, what can you infer about the original input n?

hard🔄 Reverse Engineer Q9 of Q15
Bit Manipulation - Power of Four
Given the output of the bitmask check (n & 0x55555555) == 0 is false, and (n & (n - 1)) == 0 is true, what can you infer about the original input n?
An is not a power of two
Bn is a power of two but NOT a power of four
Cn is a power of four
Dn is zero or negative
Step-by-Step Solution
Solution:
  1. Step 1: Interpret (n & (n - 1)) == 0 is true

    This means n has exactly one set bit (power of two).
  2. Step 2: Interpret (n & 0x55555555) == 0 is false

    Means the set bit is NOT in an even position, so not a power of four.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Single set bit but wrong bit position -> power of two but not four [OK]
Quick Trick: Single set bit but mask fails -> power of two not four [OK]
Common Mistakes:
MISTAKES
  • Confusing mask meaning
  • Assuming true means power of four
Trap Explanation:
PITFALL
  • Candidates often miss bit position check meaning in mask result.
Interviewer Note:
CONTEXT
  • Tests reverse reasoning from bitmask outputs
Master "Power of Four" in Bit Manipulation

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bit Manipulation Quizzes