Bird
Raised Fist0

Given the following code snippet using logarithms, what is the output of isPowerOfFour(16)?

easy🧾 Code Trace Q3 of Q15
Bit Manipulation - Power of Four
Given the following code snippet using logarithms, what is the output of isPowerOfFour(16)?
Afalse
BRaises an error
Ctrue
DDepends on floating point precision
Step-by-Step Solution
Solution:
  1. Step 1: Compute math.log2(16) / 2

    log2(16) = 4, so 4 / 2 = 2.0
  2. Step 2: Check if 2.0 equals int(2.0)

    Yes, 2.0 == 2, so returns true.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    16 is 4^2, so true is correct [OK]
Quick Trick: log2(16)/2 is integer -> true for power of four [OK]
Common Mistakes:
MISTAKES
  • Thinking floating point causes error here
  • Confusing power of two with power of four
Trap Explanation:
PITFALL
  • Some candidates doubt floating point equality but 16 is exact power of four.
Interviewer Note:
CONTEXT
  • Tests ability to trace math-based power of four check
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