|
Versions Of This Snippet::
Download a raw-text version of this code by clicking on "Download Version"
Latest Snippet Version: :1.0
#!/usr/bin/env ruby
#Used to find the correct location of the ruby instalation
# BinaryDecimalConverter.rb
version = "BinaryDecimalConverter 1.0 - copyright h4xcode 2012 - BSD Licens"
case ARGV[0]
when "-b"
number = ARGV[1].to_i # makes the argument to an int
print "Number in binary: "
print number.to_s(2)
print "\n"
when "-d"
number = ARGV[1].to_s
print "Number in decimal: "
print number.to_i(2)
print "\n"
when "-v"
puts version
else
puts <<-EOF
Please provide command name
Usage:
conbin -b decimal
-b: Decimal should be a real number
conbin -d binary
-d: binary should be a binary number
conbin -v prints the version number and copyrigth information
EOF
end
Submit a new versionYou can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..
|
||||||||||||||||||||||||||||||||||||
