Skip to content

Instantly share code, notes, and snippets.

@riywo
Created October 2, 2013 07:19
Show Gist options
  • Save riywo/6790103 to your computer and use it in GitHub Desktop.
Save riywo/6790103 to your computer and use it in GitHub Desktop.
class String
def to_bin
bytes = self.size/2
self.unpack('a2'*bytes).map{|x| x.hex}.pack('C'*bytes)
end
end
"20814804c1767293b99f1d9cab3bc3e7".to_bin #=> " \x81H\x04\xC1vr\x93\xB9\x9F\x1D\x9C\xAB;\xC3\xE7"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment