Bit Manipulation - Power of FourWhat is the output of the following code when called with isPowerOfFour(1)?AtrueBRaises an errorCfalseDDepends on floating point precisionCheck Answer
Step-by-Step SolutionSolution:Step 1: Compute math.log2(1) / 2log2(1) = 0, so 0 / 2 = 0.0Step 2: Check if 0.0 equals int(0.0)Yes, 0.0 == 0, so returns true.Final Answer:Option A -> Option AQuick Check:1 = 4^0, so true is correct [OK]Quick Trick: 1 is 4^0, so returns true [OK]Common Mistakes:MISTAKESThinking 1 is not a power of fourDoubting floating point equality at zeroTrap Explanation:PITFALLCandidates often forget 1 is a power of any number to zero power.Interviewer Note:CONTEXTTests edge case handling in logarithm approach
Master "Power of Four" in Bit Manipulation3 interactive learning modes - each teaches the same concept differentlyTry ItSolutionTrace
More Bit Manipulation Quizzes Counting Bits (0 to N) - Counting Bits (0 to N) - Quiz 15hard Counting Bits (0 to N) - Counting Bits (0 to N) - Quiz 14medium Generate All Permutations Using Bitmask DP - Generate All Permutations Using Bitmask DP - Quiz 5medium Number of 1 Bits (Hamming Weight) - Number of 1 Bits (Hamming Weight) - Quiz 15hard Number of 1 Bits (Hamming Weight) - Number of 1 Bits (Hamming Weight) - Quiz 6medium Number of 1 Bits (Hamming Weight) - Number of 1 Bits (Hamming Weight) - Quiz 3easy Reverse Bits - Reverse Bits - Quiz 14medium Single Number II (Three Copies) - Single Number II (Three Copies) - Quiz 13medium Subsets Using Bitmask - Subsets Using Bitmask - Quiz 5medium Sum of Two Integers Without + Operator - Sum of Two Integers Without + Operator - Quiz 10hard