summaryrefslogtreecommitdiff
path: root/d
diff options
context:
space:
mode:
authorNæþ'n Lasseter <Næþ'n Lasseter nathan@bytemark.co.uk>2016-09-29 14:20:52 +0100
committerNæþ'n Lasseter <Næþ'n Lasseter nathan@bytemark.co.uk>2016-09-29 14:20:52 +0100
commit0c8741059abcaaed99e627e42b99c50a17abbf08 (patch)
treeaa3e5df103066eb68d39fea0b88db68ceb5570d5 /d
parente6e6fe3cd13aaecf83cf3105c3fcd81db97481b5 (diff)
New scripts
Diffstat (limited to 'd')
-rwxr-xr-xd33
1 files changed, 33 insertions, 0 deletions
diff --git a/d b/d
new file mode 100755
index 0000000..cedcfc0
--- /dev/null
+++ b/d
@@ -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