Add Two Integers without using Arithmetic Operators

Recently came across an interesting question of adding two numbers without using any of the arithmetic operators and thought of giving it a try.

The first thought of solving the question was using bit-manipulation operations. The idea was to add the numbers bit-by-bit taking any carry forward (without actually adding them and instead using bit-wise AND/OR/XOR operators) just as we were taught to do normal arithmetic in primary classes except that here we are dealing with binary numbers instead of decimals.

The code for the same follows:

There certainly can be other approaches as well and we would appreciate our readers to share the same if they have any. 🙂

You can get the ‘C’ language version of the above code at Github.

Rate this post

Leave a Reply