Created
February 3, 2015 18:09
-
-
Save genaromadrid/d303b09a0ecefa0756c4 to your computer and use it in GitHub Desktop.
Binary & hex conversion functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bin_to_hex(s) | |
s.scrub.unpack('H*').first | |
end | |
def hex_to_bin(s) | |
s.scan(/../).map { |x| x.hex }.pack('c*') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment