class ASMOperations::Decimal

Attributes

decimal[RW]

Public Class Methods

new(decimal) click to toggle source
Calls superclass method ASMOperations::Binary::new
# File lib/types/decimal.rb, line 5
def initialize(decimal)
  @decimal = decimal
  super(self.to_binary)
end

Public Instance Methods

to_binary() click to toggle source
# File lib/types/decimal.rb, line 10
def to_binary
  remaining, _bit = decimal.to_i, 0
  bits = (remaining == 0 ? [0, 0, 0, 0] : [])

  while remaining > 0
    bits.push(remaining % 2)
    remaining /= 2
  end

  bits.reverse!
  bits.map!(&:to_s).join('')
end