From a237f7651f55d2534ecd4617e2b51f120c79dbd7 Mon Sep 17 00:00:00 2001 From: Dennis Sperzel Date: Wed, 31 Jan 2024 09:54:01 +0100 Subject: [PATCH] addition preperation for greater numbers --- src/addition.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/addition.c b/src/addition.c index 597d458..d165ae4 100644 --- a/src/addition.c +++ b/src/addition.c @@ -2,16 +2,24 @@ #include 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; } \ No newline at end of file