From 1f58e49e5539a30aeb44aafbef49e0230aafa0d0 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 01:08:59 +0100 Subject: [PATCH] multiplication by even --- src/multiplication.c | 4 ++++ src/multiplication.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/multiplication.c b/src/multiplication.c index 143fa25..3c5c479 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -60,5 +60,9 @@ int multiply_using_two_complements(int num1, int num2) { return result; } +int multiply_by_even(int num, int factor) { + return (num >> 1) << (factor + 1); +} + diff --git a/src/multiplication.h b/src/multiplication.h index dd99a1f..a3c42b1 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -11,6 +11,7 @@ int multiply_by_random(int num); int multiply_string(const char* str, int factor); int multiply_by_sum(int num1, int num2); int multiply_using_two_complements(int num1, int num2); +int multiply_by_even(int num, int factor); #endif // MULTIPLICATION_H