Method: Integer#binary

Defined in:
lib/epitools/core_ext/numbers.rb

#binary(min_length = 8) ⇒ Object Also known as: bin

Convert this number to a Ruby-style string of platform-endian binary digits (eg: “0b011010101”). Note: The min_length argument tells how long the string should be (padding the missing digits with 0’s); defaults to 8.



290
291
292
293
# File 'lib/epitools/core_ext/numbers.rb', line 290

def binary(min_length=8)
  width = (log(2).ceil / min_length.to_f).ceil * min_length
  "0b%0.#{width}b" % self
end