Tuesday, May 5, 2015

Subtract two numbers using bit manipulation

Subtracting numbers is done similar to add number(refer previous post in this blog) with minor difference. Instead of direct and between x and y . We take negation of x to and.

Adding two numbers using bit manipulation

Adding of two numbers can be done with bit manipulation. The operation if we examine atomically mirrors the actual operation we do while adding two numbers. Here is sample code: