Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
val = "a0192faa0"
function string.pack(str)
local packed_string = "" for i=1, #str, 2 do
local hex_number = tonumber("0x" .. str:sub(i,i) .. str:sub(i+1,i+1))
packed_string = packed_string .. string.char(hex_number)
end return packed_string
end
print("==========")
print(val)
print("==========")
binary_string = string.pack(val)
print(binary_string, type(binary_string), #binary_string)
print("==========")
for i=1, #binary_string do
print(string.byte(binary_string, i), string.format("%x", string.byte(binary_string, i)))
end
print("==========")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment