Binary Algorithm Summaries
Continuing through the Blind 75 summarizations, here are the binary-related questions. There are not many tricks with these questions, this is just testing knowledge on binary operations. Sum of Two Integers Find sum of two integers without using built in integer operators. Solution with O(1)/O(1): Use binary operators: Take binary AND of the input integers, shift left 1, that is the carry Take binary XOR of the input integers, that is the result Recursively repeat with result and carry instead of the input integers, until the carry is 0 Number of 1 Bits Given an integer, return the number of 1 bits in its binary representation. ...