#include<stdio.h>
typedef char bit;
bit carry = 0;
bit halfadd( bit A, bit B ){
carry = A & B;
return A ^ B;
}
bit fulladd( bit A, bit B ){
bit xor = A ^ B;
bit ret = carry ^ xor;
carry = (carry & xor) | (A & B);
return ret;
}
void fillNum( int num, bit *array ){
int i;
for( i = 0; i < 32; ++ i ){
array[i] = ( num >> i ) & 1;
}
}
int main(){
bit num1[32] = {0}, num2[32] = {0};
int A = 64620926, B = 1531529858;
fillNum( A, num1 );
fillNum( B, num2 );
int r = 0;
bit tmp = 0;
// bit tmp = halfadd( num1[0], num2[0] );
// putchar( tmp ? '1' : '0' );
// r = tmp;
int i;
for( i = 1; i < 32; ++i ){
tmp = fulladd( num1[i], num2[i] );
r += tmp << i;
}
printf("\n%d\n\n%d + %d = %d", r
, A
, B
, A
+B
); return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KIAp0eXBlZGVmIGNoYXIgYml0OwpiaXQgY2FycnkgPSAwOwpiaXQgaGFsZmFkZCggYml0IEEsIGJpdCBCICl7CiAgICBjYXJyeSA9IEEgJiBCOwogICAgcmV0dXJuIEEgXiBCOwp9CmJpdCBmdWxsYWRkKCBiaXQgQSwgYml0IEIgKXsKICAgIGJpdCB4b3IgPSBBIF4gQjsKICAgIGJpdCByZXQgPSBjYXJyeSBeIHhvcjsKICAgIGNhcnJ5ID0gKGNhcnJ5ICYgeG9yKSB8IChBICYgQik7CiAgICByZXR1cm4gcmV0OyAKfQoKdm9pZCBmaWxsTnVtKCBpbnQgbnVtLCBiaXQgKmFycmF5ICl7CiAgICBpbnQgaTsKICAgIGZvciggaSA9IDA7IGkgPCAzMjsgKysgaSApewogICAgICAgIGFycmF5W2ldID0gKCBudW0gPj4gaSApICYgMTsKICAgIH0KfQoKaW50IG1haW4oKXsgCiAgICBiaXQgbnVtMVszMl0gPSB7MH0sIG51bTJbMzJdID0gezB9OwogICAgaW50IEEgPSA2NDYyMDkyNiwgQiA9IDE1MzE1Mjk4NTg7CiAgICBmaWxsTnVtK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