Sum two numbers using bits

int main(int argc,char *argv[]){
int a=atoi(argv[1]),b=atoi(argv[2]),sum,carry;

sum = a^b;
carry = a&b;
while(carry){
carry = carry << 1; int newsum = sum ^ carry; carry = sum & carry; sum = newsum; } printf("Output is %d+%d=%dn",a,b,sum); }

Leave a Reply

Your email address will not be published. Required fields are marked *