class Aruba::Contracts::IsPowerOfTwo
Is value power of two
Public Class Methods
valid?(value)
click to toggle source
Check value
@param [Integer] value
The value to be checked
# 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