diff options
author | Næþ'n Lasseter <Næþ'n Lasseter nathan@bytemark.co.uk> | 2016-09-29 14:20:52 +0100 |
---|---|---|
committer | Næþ'n Lasseter <Næþ'n Lasseter nathan@bytemark.co.uk> | 2016-09-29 14:20:52 +0100 |
commit | 0c8741059abcaaed99e627e42b99c50a17abbf08 (patch) | |
tree | aa3e5df103066eb68d39fea0b88db68ceb5570d5 /d | |
parent | e6e6fe3cd13aaecf83cf3105c3fcd81db97481b5 (diff) |
New scripts
Diffstat (limited to 'd')
-rwxr-xr-x | d | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -0,0 +1,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 |