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
      15 16 17 18 19 20 21  | 
    
      # File 'lib/aruba/contracts/is_power_of_two.rb', line 15 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  |