Bird
Raised Fist0

What is the output of the following code when called with isPowerOfFour(1)?

medium🧾 Code Trace Q4 of Q15
Bit Manipulation - Power of Four
What is the output of the following code when called with isPowerOfFour(1)?
Atrue
BRaises an error
Cfalse
DDepends on floating point precision
Step-by-Step Solution
Solution:
  1. Step 1: Compute math.log2(1) / 2

    log2(1) = 0, so 0 / 2 = 0.0
  2. Step 2: Check if 0.0 equals int(0.0)

    Yes, 0.0 == 0, so returns true.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    1 = 4^0, so true is correct [OK]
Quick Trick: 1 is 4^0, so returns true [OK]
Common Mistakes:
MISTAKES
  • Thinking 1 is not a power of four
  • Doubting floating point equality at zero
Trap Explanation:
PITFALL
  • Candidates often forget 1 is a power of any number to zero power.
Interviewer Note:
CONTEXT
  • Tests edge case handling in logarithm approach
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