K
K
kate2018-09-17 00:00:08
Mathematics
kate, 2018-09-17 00:00:08

What is "binary exponentiation"?

On the Internet I saw only incomprehensible code examples, please explain in words, or with an example.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alex_ak1, 2018-09-17
@alex_ak1

r := 1;
while (pow > 0) do
if (pow mod 2 = 1) then
begin
r := r * a;
pow := pow-1;
end
else
begin
r := r * r;
pow := pow div 2;
end;
Thus exponentiation takes a little more than ln2(pow) operations, not pow operations.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question