Bit Manipulation - Power of FourGiven the following Python code, what is the output of isPowerOfFour(16)?ATrueBFalseCRaises an error due to floating point precisionDNoneCheck Answer
Step-by-Step SolutionSolution:Step 1: Calculate log2(16)log2(16) = 4, dividing by 2 gives 2.0.Step 2: Check if 2.0 equals int(2.0)2.0 == 2 is True, so the function returns True.Final Answer:Option A -> Option AQuick Check:16 is 4^2, so output True is expected [OK]Quick Trick: log2(16)/2 = 2.0 equals int(2) -> TrueCommon Mistakes:MISTAKESAssuming floating point error causes failureConfusing power of two with power of fourTrap Explanation:PITFALLFloating point equality can fail for some inputs, but 16 is exact power so no error here.Interviewer Note:CONTEXTChecks candidate's ability to trace floating point calculations and understand the logic.
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