binary addition using bitwise operators

Solutions on MaxInterview for binary addition using bitwise operators by the best coders in the world

showing results for - "binary addition using bitwise operators"
Irene
22 Sep 2016
1#include<stdio.h>
2 
3int bitwiseadd(int x, int y)
4{
5    while (y != 0)
6    {
7        int carry = x & y;
8        x = x ^ y; 
9        y = carry << 1;
10    }
11    return x;
12}
13 
14int main()
15{
16    int num1, num2;
17    printf("\nEnter two numbers to perform addition using bitwise operators: ");
18    scanf("%d%d", &num1, &num2);
19    printf("\nSum is %d", bitwiseadd(num1, num2));
20    return 0;
21}