Class: Aruba::Contracts::IsPowerOfTwo
- Inherits:
-
Object
- Object
- Aruba::Contracts::IsPowerOfTwo
- Defined in:
- lib/aruba/contracts/is_power_of_two.rb
Overview
Is value power of two
Class Method Summary collapse
-
.valid?(value) ⇒ Boolean
Check value.
Class Method Details
.valid?(value) ⇒ Boolean
Check value
13 14 15 16 17 18 19 |
# File 'lib/aruba/contracts/is_power_of_two.rb', line 13 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 & (value - 1)).zero? rescue StandardError false end |