class Zold::Hexnum

A hex num

Public Class Methods

new(num, length) click to toggle source
# File lib/zold/hexnum.rb, line 31
def initialize(num, length)
  @num = num
  @length = length
end
parse(txt) click to toggle source
# File lib/zold/hexnum.rb, line 44
def self.parse(txt)
  n = Integer("0x#{txt}", 16)
  if txt.start_with?('f')
    max = Integer("0x#{'f' * txt.length}", 16)
    n = n - max - 1
  end
  Hexnum.new(n, txt.length)
end

Public Instance Methods

to_i() click to toggle source
# File lib/zold/hexnum.rb, line 36
def to_i
  @num
end
to_s() click to toggle source
# File lib/zold/hexnum.rb, line 40
def to_s
  format("%0#{@length}x", @num).gsub(/^\.{2}/, 'ff')
end