From ccb098243951821e32986f6017c954849ecb8a12 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 13:25:05 +0100 Subject: [PATCH] bitwise multiplication fonction added --- src/multiplication.c | 13 +++++++++++++ src/multiplication.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/src/multiplication.c b/src/multiplication.c index 0734802..062c50b 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -219,6 +219,19 @@ float power_multiply(float base, int exponent) { return result; } +int bitwise_multiply(int num1, int num2) { + int result = 0; + while (num1) { + if (num1 & 1) { + result += num2; + } + num1 >>= 1; + num2 <<= 1; + } + return result; +} + + diff --git a/src/multiplication.h b/src/multiplication.h index c29b077..342bd91 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -30,6 +30,8 @@ int fibonacci_multiply(int num, int fib); int repeated_division_multiply(int num1, int num2); int bernoulli_multiply(int num, int bernoulli); float power_multiply(float base, int exponent); +int bitwise_multiply(int num1, int num2); +