Bit Manipulation - Power of TwoGiven the following code, what is the output of isPowerOfTwo(16)?AErrorBFalseCTrueDNoneCheck Answer
Step-by-Step SolutionSolution:Step 1: Evaluate input 1616 in binary is 10000. 16 - 1 = 15 (01111).Step 2: Compute n & (n - 1)10000 & 01111 = 00000, which equals 0, so function returns True.Final Answer:Option C -> Option CQuick Check:16 is a power of two, so output is True [OK]Quick Trick: n & (n-1) == 0 means power of two [OK]Common Mistakes:MISTAKESMiscompute bitwise ANDForget to check n > 0Trap Explanation:PITFALLCandidates sometimes confuse bitwise AND result or forget zero check.Interviewer Note:CONTEXTTests ability to trace bitwise operations on simple input.
Master "Power of Two" in Bit Manipulation3 interactive learning modes - each teaches the same concept differentlyTry ItSolutionTrace
More Bit Manipulation Quizzes Bitwise AND of Numbers Range - Bitwise AND of Numbers Range - Quiz 2easy Gray Code - Gray Code - Quiz 15hard Maximum Product of Word Lengths - Maximum Product of Word Lengths - Quiz 6medium Maximum Product of Word Lengths - Maximum Product of Word Lengths - Quiz 8hard Number of 1 Bits (Hamming Weight) - Number of 1 Bits (Hamming Weight) - Quiz 6medium Power of Four - Power of Four - Quiz 7medium Reverse Bits - Reverse Bits - Quiz 8hard Single Number II (Three Copies) - Single Number II (Three Copies) - Quiz 3easy Single Number III (Two Singles) - Single Number III (Two Singles) - Quiz 6medium UTF-8 Validation - UTF-8 Validation - Quiz 1easy