Skip to content

Commit

Permalink
perf: use bitwise and instead of modulus
Browse files Browse the repository at this point in the history
  • Loading branch information
PraneethJain committed Nov 16, 2023
1 parent ab42005 commit 5d4886d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion math/binary_exponentiation.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int64_t binary_exponentiation(int64_t base, uint64_t exponent)
int64_t result = 1;
while (exponent > 0)
{
if (exponent % 2 == 1) // If the current bit is 1
if (exponent & 1) // If the current bit is 1
{
result *= base; // Then it must be multiplied to the result
}
Expand Down

0 comments on commit 5d4886d

Please sign in to comment.