CountBits
not ratedFinds the number of bits an integer needs.
function CountBits takes integer val returns integer
local integer i = 0
local integer tmp = 0
if val == 0 then
return 1
endif
loop
exitwhen tmp > val
set tmp = tmp + R2I(Pow(2,i))
set i = i + 1
endloop
return i
endfunctionNo comments.