Bit Manipulation - Power of FourGiven the following code snippet using logarithms, what is the output of isPowerOfFour(16)?AfalseBRaises an errorCtrueDDepends on floating point precisionCheck Answer
Step-by-Step SolutionSolution:Step 1: Compute math.log2(16) / 2log2(16) = 4, so 4 / 2 = 2.0Step 2: Check if 2.0 equals int(2.0)Yes, 2.0 == 2, so returns true.Final Answer:Option C -> Option CQuick 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:MISTAKESThinking floating point causes error hereConfusing power of two with power of fourTrap Explanation:PITFALLSome candidates doubt floating point equality but 16 is exact power of four.Interviewer Note:CONTEXTTests ability to trace math-based power of four check
Master "Power of Four" in Bit Manipulation3 interactive learning modes - each teaches the same concept differentlyTry ItSolutionTrace
More Bit Manipulation Quizzes Find Two Missing Numbers - Find Two Missing Numbers - Quiz 14medium Maximum XOR of Two Numbers - Maximum XOR of Two Numbers - Quiz 8hard Reverse Bits - Reverse Bits - Quiz 7medium Single Number (XOR Self-Cancellation) - Single Number (XOR Self-Cancellation) - Quiz 13medium Single Number (XOR Self-Cancellation) - Single Number (XOR Self-Cancellation) - Quiz 4medium Single Number (XOR Self-Cancellation) - Single Number (XOR Self-Cancellation) - Quiz 15hard Single Number (XOR Self-Cancellation) - Single Number (XOR Self-Cancellation) - Quiz 10hard Single Number II (Three Copies) - Single Number II (Three Copies) - Quiz 7medium Single Number III (Two Singles) - Single Number III (Two Singles) - Quiz 12easy UTF-8 Validation - UTF-8 Validation - Quiz 3easy