Class: Aruba::Configuration::IsPowerOfTwo

Inherits:
Object
  • Object
show all
Defined in:
lib/aruba/configuration.rb

Overview

Value is a power of two

Class Method Summary collapse

Class Method Details

.valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
# File 'lib/aruba/configuration.rb', line 35

def self.valid?(value)
  # explanation for algorithm can be found here:
  # http://www.exploringbinary.com/ten-ways-to-check-if-an-integer-is-a-power-of-two-in-c/
  value.positive? && value.nobits?(value - 1)
rescue StandardError
  false
end