sum_bits

Declaration

sum_bits (bit_field: INTEGER): INTEGER

Description

Return the number of bits in bit_field that are set to 1. You can set bits with set_bit.

See Also

set_bit
get_bit
math functions

Example

script test_bits is
  flags := 0
  flags := set_bit (flags, 0, True) -- flags = 1
  flags := set_bit (flags, 7, True) -- flags = 10000001
  total := sum_bits (flags) -- total = 2
  flags := set_bit (flags, 0, False) -- flags = 10000000
  total := sum_bits (flags) -- total = 1
end