Problem
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.
Follow up
Write a function Add(a, b)
that returns the sum of two integers without using any arithmetic operators (+
, -
, *
, /
, ++
, --
, etc.). Use only bitwise operators and shifts where needed.
Examples
Example 1
|
|
Solution
See Method 1 and Method 2 of Sum of two numbers using only bitwise operators, and here is the video explaining this method in detail. Please check it out: