Module: Utilities::Numbers
- Defined in:
- lib/utilities/numbers.rb
Class Method Summary collapse
-
.get_bits(number) ⇒ Array
Of numbers 0 - 32.
Class Method Details
.get_bits(number) ⇒ Array
Returns of numbers 0 - 32.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/utilities/numbers.rb', line 5 def self.get_bits(number) # created by Jim Tucker, 20161012 # parameter is decimal number representing a bit map # returns an array of bits set (power of 2) starting at 0, e.g., [0, 3, 22] # use to decode StatusFlags in SF.tblTaxa ret_val = [] counter = 0 until number == 0 ret_val << counter unless (number & 1) == 0 # << = push counter += 1 number >>= 1 # >>= = right shift end ret_val end |