Browse Source

multiplication using logical operations

remotes/origin/multiplication
fdai7930 11 months ago
parent
commit
c9ef902922
  1. 12
      src/multiplication.c
  2. 1
      src/multiplication.h

12
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;
}

1
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

Loading…
Cancel
Save