Answers for "binary addition using bitwise operators"

C++
1

binary addition using bitwise operators

#include<stdio.h>
 
int bitwiseadd(int x, int y)
{
    while (y != 0)
    {
        int carry = x & y;
        x = x ^ y; 
        y = carry << 1;
    }
    return x;
}
 
int main()
{
    int num1, num2;
    printf("\nEnter two numbers to perform addition using bitwise operators: ");
    scanf("%d%d", &num1, &num2);
    printf("\nSum is %d", bitwiseadd(num1, num2));
    return 0;
}
Posted by: Guest on April-08-2021

Code answers related to "binary addition using bitwise operators"

Browse Popular Code Answers by Language