diff --git a/src/multiplication.c b/src/multiplication.c index 9cbc11f..06056de 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -80,5 +80,17 @@ int multiply_using_lookup_table(int num1, int num2) { return lookup_table[num1][num2]; } +int multiply_using_logical_operations(int num1, int num2) { + int result = 0; + while (num2) { + if (num2 & 1) { + result ^= num1; + } + num1 <<= 1; + num2 >>= 1; + } + return result; +} + diff --git a/src/multiplication.h b/src/multiplication.h index 378e860..b242c9b 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -13,6 +13,7 @@ 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); int multiply_using_lookup_table(int num1, int num2); +int multiply_using_logical_operations(int num1, int num2); #endif // MULTIPLICATION_H