Skip to content

Instantly share code, notes, and snippets.

@koichiro
Created June 25, 2014 02:27
Show Gist options
  • Save koichiro/2efb70d683c09336a488 to your computer and use it in GitHub Desktop.
Save koichiro/2efb70d683c09336a488 to your computer and use it in GitHub Desktop.
# "\x34AC23"
def hex2bin s
s = s[2, s.length]
raise "Not a valid hex string" unless(s =~ /^[\da-fA-F]+$/)
r = s.scan(/../).map{ |b| b.to_i(16) }.pack('C*')
r.force_encoding("UTF-8")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment