module ToBinary
Public Instance Methods
to_binary(length = 0)
click to toggle source
# File lib/to_binary.rb, line 2 def to_binary length = 0 n = self b = [self == 0 ? 0 : nil] while n > 0 b.unshift n % 2 n /= 2 end (length-b.size + 1).times { b.unshift 0 } b.join end