Bird
Raised Fist0

Given the following Python code, what is the output of isPowerOfFour(16)?

easy🧾 Code Trace Q12 of Q15
Bit Manipulation - Power of Four
Given the following Python code, what is the output of isPowerOfFour(16)?
ATrue
BFalse
CRaises an error due to floating point precision
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Calculate log2(16)

    log2(16) = 4, dividing by 2 gives 2.0.
  2. Step 2: Check if 2.0 equals int(2.0)

    2.0 == 2 is True, so the function returns True.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    16 is 4^2, so output True is expected [OK]
Quick Trick: log2(16)/2 = 2.0 equals int(2) -> True
Common Mistakes:
MISTAKES
  • Assuming floating point error causes failure
  • Confusing power of two with power of four
Trap Explanation:
PITFALL
  • Floating point equality can fail for some inputs, but 16 is exact power so no error here.
Interviewer Note:
CONTEXT
  • Checks candidate's ability to trace floating point calculations and understand the logic.
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