2022-11-05 16:48:47 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-29 10:09:10 +00:00
|
|
|
# turn byte array into hex string
|
|
|
|
def str_hex(data)
|
2022-11-05 16:19:05 +00:00
|
|
|
data.unpack1('H*').scan(/../).join(' ').upcase
|
2022-10-29 10:09:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# turn hex string to byte array
|
|
|
|
def str_bytes(str)
|
2022-11-05 16:19:05 +00:00
|
|
|
str.scan(/../).map { |b| b.to_i(16) }
|
2022-10-29 10:09:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def bytes_to_str(data)
|
2022-11-05 16:19:05 +00:00
|
|
|
data.unpack('H*').join('')
|
2022-10-29 10:09:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_byte(data, start = 0, num = 1)
|
2022-11-05 16:19:05 +00:00
|
|
|
data[start...(start + num)].unpack('H*').join('').upcase
|
2022-10-29 10:09:10 +00:00
|
|
|
end
|