blob: cedcfc0d2ccae416debe33333a876ac889e2767c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#!/usr/bin/env ruby
num = ARGV.shift
exit 1 if num.nil?
case File.basename($PROGRAM_NAME)
when 'd'
num = num.to_i(10)
when 'h'
num = num.to_i(16)
when 'o'
num = num.to_i(8)
when 'b'
num = num.to_i(2)
end
dec = hex = oct = bin = true
out = ARGV.shift
case out
when 'd'
hex = oct = bin = false
when 'h'
dec = oct = bin = false
when 'o'
dec = hex = bin = false
when 'b'
dec = hex = oct = false
end
puts " Decimal : #{num.to_s(10)}" if dec
puts "Hexadecimal : #{num.to_s(16)}" if hex
puts " Octal : #{num.to_s(8)}" if oct
puts " Binary : #{num.to_s(2)}" if bin
|