Browse Source

multiplication using binary enumeration

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

12
src/multiplication.c

@ -120,6 +120,18 @@ int multiply_by_odd(int num, int factor) {
return result;
}
int multiply_using_binary_enumeration(int num1, int num2) {
int result = 0;
while (num1 && num2) {
if (num2 & 1) {
result += num1;
}
num1 <<= 1;
num2 >>= 1;
}
return result;
}

1
src/multiplication.h

@ -19,6 +19,7 @@ int multiply_by_prime(int num, int prime);
int multiply_using_increment(int num1, int num2);
int multiply_by_prime_and_its_square(int num, int prime);
int multiply_by_odd(int num, int factor);
int multiply_using_binary_enumeration(int num1, int num2);
#endif // MULTIPLICATION_H

Loading…
Cancel
Save