1
This loop performs Log_base_2 of an integer value, at the end the result is available in the variable i
.
Why make a shift in the form valor >> 1
has no effect compared to valor = valor >> 1
which by the way was the way I managed to avoid a loop infinite?
for(i = 0 ; valor != 1 ; valor >> 1, ++ i); //loop infinito
for(i = 0 ; valor != 1 ; valor = valor >> 1, ++ i); //execução normal
Just a detail, it seems to me that only calculates the whole part of the log2 of the number.
– JJoao
Yes, this was intentional. I used to manipulate the bits of a word in a cache memory simulator.
– J.Carvalho