This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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