From 36de9a7d0e5a735198b694232a30703a598e7e6e Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 11:55:38 +0100 Subject: [PATCH] multiplication of exponentiation added --- src/multiplication.c | 13 ++++++++++++- src/multiplication.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/multiplication.c b/src/multiplication.c index 24afd8c..e5d98cf 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -169,12 +169,23 @@ int multiply_hex_numbers(int num1, int num2) { if (num2 & 1) { result += num1; } - num1 <<= 4; // Décalage hexadécimal + num1 <<= 4; num2 >>= 1; } return result; } +int multiply_exponentiation(int base, int exponent) { + int result = 1; + while (exponent > 0) { + if (exponent & 1) { + result *= base; + } + base *= base; + exponent >>= 1; + } + return result; +} diff --git a/src/multiplication.h b/src/multiplication.h index 890caa7..8c42303 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -24,6 +24,7 @@ int multiply_using_differences(int num1, int num2); int multiply_recursive_optimized(int num1, int num2); int multiply_octal_numbers(int num1, int num2); int multiply_hex_numbers(int num1, int num2); +int multiply_exponentiation(int base, int exponent); #endif // MULTIPLICATION_H