Warcraft III resources & community, 2003–2006 · archived

CountBits

not rated
Submitted by Aiursrage2kCalculations0 downloads
Finds the number of bits an integer needs.

Source

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
endfunction

Comments

0

No comments.