Bit Manipulation - Sum of Two Integers Without + OperatorWhat is the output of getSum(-2, 3) using the recursive bitwise sum function below?A-5B1C0D-1Check Answer
Step-by-Step SolutionSolution:Step 1: Convert inputs to 32-bit mask-2 in 32-bit unsigned is 0xFFFFFFFE, 3 is 0x00000003.Step 2: Trace recursive callssum_ = (0xFFFFFFFE XOR 3) & MASK = 0xFFFFFFFD, carry = ((0xFFFFFFFE & 3) << 1) & MASK = 4; next call getSum(0xFFFFFFFD, 4)Step 3: Continue until carry is 0Eventually returns 1, which is the sum of -2 + 3.Final Answer:Option B -> Option BQuick Check:-2 + 3 = 1 matches output [OK]Quick Trick: Masking handles negative numbers correctly [OK]Common Mistakes:MISTAKESIgnoring masking leads to wrong negative resultsTrap Explanation:PITFALLCandidates often forget to mask or handle sign bits, causing wrong output.Interviewer Note:CONTEXTTests handling of negative numbers and masking in bitwise sum
Master "Sum of Two Integers Without + Operator" 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 13medium Bitwise AND of Numbers Range - Bitwise AND of Numbers Range - Quiz 7medium Maximum Product of Word Lengths - Maximum Product of Word Lengths - Quiz 9hard Maximum Product of Word Lengths - Maximum Product of Word Lengths - Quiz 7medium Power of Two - Power of Two - Quiz 15hard Reverse Bits - Reverse Bits - Quiz 10hard Single Number (XOR Self-Cancellation) - Single Number (XOR Self-Cancellation) - Quiz 11easy Single Number III (Two Singles) - Single Number III (Two Singles) - Quiz 1easy Single Number III (Two Singles) - Single Number III (Two Singles) - Quiz 3easy UTF-8 Validation - UTF-8 Validation - Quiz 9hard