I recently saw that representation in here: https://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method
'exponent := exponent >> 1'
what does it mean?
I recently saw that representation in here: https://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method
'exponent := exponent >> 1'
what does it mean?
It is actually a right-shift operator.
Right-shifting a number by 1 is the same as dividing it by two.
That looks like shift right (which effectively divides by two).
It's a bit odd that the example uses mod
and >>
. I'd expect & 1
and >> 1
or mod 2
and / 2
for consistency