How to implement binary addition in C

1 Answer

0 votes
#include <stdio.h>

int BinaryAddition(int a, int b) {
    int carry;

    while (b != 0) {
        carry = (a & b) << 1;
        a = a ^ b;
        b = carry;
    }

    return a;
}


int main()
{
    int number1 = 8, number2 = 3;

    printf("%d", BinaryAddition(number1, number2));
 
    return 0;
}



/*
run:

11

*/

 



answered May 12, 2023 by avibootz

Related questions

1 answer 113 views
113 views asked May 12, 2023 by avibootz
1 answer 159 views
2 answers 204 views
1 answer 181 views
1 answer 177 views
...