Bird
Raised Fist0

Given the output of isPowerOfTwo(218) is False, which of the following inputs would produce True for the same function?

hard🔄 Reverse Engineer Q9 of Q15
Bit Manipulation - Power of Two
Given the output of isPowerOfTwo(218) is False, which of the following inputs would produce True for the same function?
A218
B256
C219
D0
Step-by-Step Solution
Solution:
  1. Step 1: Understand why 218 returns False

    218 in binary has multiple set bits, so n & (n - 1) != 0.
  2. Step 2: Identify input with single set bit

    256 is 2^8, binary 100000000, so n & (n - 1) == 0, returns True.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Only powers of two return True [OK]
Quick Trick: Only powers of two have one set bit [OK]
Common Mistakes:
MISTAKES
  • Choosing non-power of two numbers
  • Ignoring zero and negative inputs
Trap Explanation:
PITFALL
  • Candidates confuse numbers close to powers of two with actual powers of two.
Interviewer Note:
CONTEXT
  • Tests reverse reasoning from output to input properties.
Master "Power of Two" 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