diff options
author | Nat Lasseter <Nat Lasseter nathan@bytemark.co.uk> | 2017-07-18 16:25:40 +0100 |
---|---|---|
committer | Nat Lasseter <Nat Lasseter nathan@bytemark.co.uk> | 2017-07-18 16:25:40 +0100 |
commit | f9e60751846f79c37925946b32528db2d0e66dbd (patch) | |
tree | 5a14f4811ca21cce45db461e464aeac0ac982617 /d | |
parent | 5a2fb234cf6c750518bd265256af3e956ffc2193 (diff) |
Added dozenal to d
Diffstat (limited to 'd')
-rwxr-xr-x | d | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -6,6 +6,8 @@ exit 1 if num.nil? case File.basename($PROGRAM_NAME) when 'd' num = num.to_i(10) +when 'z' + num = num.gsub(/x/i, 'a').gsub(/e/i, 'b').to_i(12) when 'h' num = num.to_i(16) when 'o' @@ -16,22 +18,26 @@ when 'c' num = num.ord end -dec = hex = oct = bin = char = true +dec = doz = hex = oct = bin = true +char = num > 31 && num < 128 out = ARGV.shift case out when 'd' - hex = oct = bin = char = false + doz = hex = oct = bin = char = false +when 'z' + dec = hex = oct = bin = char = false when 'h' - dec = oct = bin = char = false + dec = doz = oct = bin = char = false when 'o' - dec = hex = bin = char = false + dec = doz = hex = bin = char = false when 'b' - dec = hex = oct = char = false + dec = doz = hex = oct = char = false when 'c' - dec = hex = oct = bin = false + dec = doz = hex = oct = bin = false end puts " Decimal : #{num.to_s(10)}" if dec +puts " Dozenal : #{num.to_s(12).gsub(/a/, 'X').gsub(/b/, 'E')}" if doz puts "Hexadecimal : 0x#{num.to_s(16)}" if hex puts " Octal : 0#{num.to_s(8)}" if oct puts " Binary : 0b#{num.to_s(2)}" if bin |