18 lines
361 B
Ruby
18 lines
361 B
Ruby
# turn byte array into hex string
|
|
def str_hex(data)
|
|
data.unpack1('H*').scan(/../).join(' ').upcase
|
|
end
|
|
|
|
# turn hex string to byte array
|
|
def str_bytes(str)
|
|
str.scan(/../).map { |b| b.to_i(16) }
|
|
end
|
|
|
|
def bytes_to_str(data)
|
|
data.unpack('H*').join('')
|
|
end
|
|
|
|
def get_byte(data, start = 0, num = 1)
|
|
data[start...(start + num)].unpack('H*').join('').upcase
|
|
end
|