Method: String#unhexlify
- Defined in:
-
lib/amp/dependencies/amp_support/ruby_amp_support.rb,
lib/amp/dependencies/amp_support/ruby_amp_support.rb,
ext/amp/support/support.c
Converts a string of hexademical into its binary representation. Method on strings. When the data in the string is hexademical (such as “DEADBEEF”), this method decodes the hex and converts every 2 bytes into its 1-byte binary representation.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/amp/dependencies/amp_support/ruby_amp_support.rb', line 79 def unhexlify str = "\000" * (size/2) c = 0 (0..size-2).step(2) do |i| hex = self[i,2].to_i(16) str[c] = hex c += 1 end str end |