Skip to content

Instantly share code, notes, and snippets.

@6david9
Created October 23, 2014 06:25
Show Gist options
  • Save 6david9/57e28b158e9e5a84f3bf to your computer and use it in GitHub Desktop.
Save 6david9/57e28b158e9e5a84f3bf to your computer and use it in GitHub Desktop.
hex to binary
str = ARGF.argv[0].strip.downcase
if str.start_with? '0x'
str.delete! '0x'
end
str.each_char do |c|
bin = c.to_i(16).to_s(2)
bin.insert(0, '0' * (4-bin.length)) if bin.length < 4
print "#{bin} "
end
print "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment