|
|
@ -2,16 +2,24 @@ |
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
void full_adder (unsigned int* sum, unsigned int* nextcarry, unsigned int number1, unsigned int number2, unsigned int carry) { |
|
|
|
sum[0] = number1 ^ number2 ^ carry; |
|
|
|
sum[0] = (number1 % 2) ^ (number2 % 2) ^ (carry % 2); |
|
|
|
|
|
|
|
nextcarry[0] = (number1 & number2) | (number1 & carry) | (number2 & carry); |
|
|
|
nextcarry[0] = ((number1 % 2) & (number2 % 2)) | ((number1 % 2) & (carry % 2)) | ((number2 % 2) & (carry % 2)); |
|
|
|
} |
|
|
|
|
|
|
|
unsigned int addition(unsigned int a, unsigned int b) { |
|
|
|
unsigned int s[1]; |
|
|
|
unsigned int erg = 0; |
|
|
|
unsigned int s[1] = {0}; |
|
|
|
unsigned int nc[1] = {0}; |
|
|
|
|
|
|
|
full_adder(s, nc, a, b, 0); |
|
|
|
for (int i = 0; i < 2; i++) |
|
|
|
{ |
|
|
|
full_adder(s, nc, a, b, nc[0]); |
|
|
|
erg ^= (s[0] << i); |
|
|
|
|
|
|
|
return s[0] ^ (nc[0] << 1); |
|
|
|
a >>= 1; |
|
|
|
b >>= 1; |
|
|
|
} |
|
|
|
|
|
|
|
return erg; |
|
|
|
} |