module Binascii::Hex

Constants

A2B_HI
A2B_LO
B2A

Public Instance Methods

a2b_hex(data) click to toggle source
# File lib/binascii/hex.rb, line 27
def a2b_hex(data)
  String.new('', encoding: 'ASCII-8BIT').tap do |result|
    len = data.bytesize
    pos = 0

    while pos < len
      result << (A2B_HI[data.getbyte(pos)] | A2B_LO[data.getbyte(pos + 1)])
      pos += 2
    end
  end
end
Also aliased as: unhexlify
b2a_hex(data) click to toggle source
# File lib/binascii/hex.rb, line 17
def b2a_hex(data)
  String.new('', encoding: 'ASCII-8BIT').tap do |result|
    data.each_byte do |byte|
      result << B2A[byte]
    end
  end
end
Also aliased as: hexlify
hexlify(data)
Alias for: b2a_hex
unhexlify(data)
Alias for: a2b_hex