Bit Manipulation - Power of TwoGiven the output of isPowerOfTwo(218) is False, which of the following inputs would produce True for the same function?A218B256C219D0Check Answer
Step-by-Step SolutionSolution:Step 1: Understand why 218 returns False218 in binary has multiple set bits, so n & (n - 1) != 0.Step 2: Identify input with single set bit256 is 2^8, binary 100000000, so n & (n - 1) == 0, returns True.Final Answer:Option B -> Option BQuick Check:Only powers of two return True [OK]Quick Trick: Only powers of two have one set bit [OK]Common Mistakes:MISTAKESChoosing non-power of two numbersIgnoring zero and negative inputsTrap Explanation:PITFALLCandidates confuse numbers close to powers of two with actual powers of two.Interviewer Note:CONTEXTTests reverse reasoning from output to input properties.
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 12easy Bitwise AND of Numbers Range - Bitwise AND of Numbers Range - Quiz 13medium Generate All Permutations Using Bitmask DP - Generate All Permutations Using Bitmask DP - Quiz 14medium Gray Code - Gray Code - Quiz 10hard Maximum Product of Word Lengths - Maximum Product of Word Lengths - Quiz 14medium Number of 1 Bits (Hamming Weight) - Number of 1 Bits (Hamming Weight) - Quiz 9hard Reverse Bits - Reverse Bits - Quiz 8hard Single Number II (Three Copies) - Single Number II (Three Copies) - Quiz 6medium Single Number III (Two Singles) - Single Number III (Two Singles) - Quiz 13medium UTF-8 Validation - UTF-8 Validation - Quiz 1easy