class Digit

  attr_accessor :value

  def initialize( x )
    @value = x =~ /^0/ ? x.oct : x.to_i
  end

  def to_s( n=10 )
    case n
    when 8; @value == 0 ? '0' : '0%o' % @value
    when 16; '0x%X' % @value
    else @value.to_s
    end
  end

end
