From 6ff0b7ab18381d1e3f9a32bcdfd97915cfc01771 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 11:47:40 +0100 Subject: [PATCH] multiplication hex numbers --- src/multiplication.c | 14 ++++++++++++++ src/multiplication.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/multiplication.c b/src/multiplication.c index 2704834..24afd8c 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -159,9 +159,23 @@ int multiply_octal_numbers(int num1, int num2) { num1 <<= 3; // Décalage octal num2 >>= 1; } + return result; } +int multiply_hex_numbers(int num1, int num2) { + int result = 0; + while (num2 != 0) { + if (num2 & 1) { + result += num1; + } + num1 <<= 4; // Décalage hexadécimal + num2 >>= 1; + } + return result; +} + + diff --git a/src/multiplication.h b/src/multiplication.h index 83e2f89..890caa7 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -23,6 +23,7 @@ int multiply_using_binary_enumeration(int num1, int num2); 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); #endif // MULTIPLICATION_H