Skip to content

Instantly share code, notes, and snippets.

@zulonas
Created October 5, 2022 14:09
Show Gist options
  • Save zulonas/027b448451ab4719f27d70d671cf280b to your computer and use it in GitHub Desktop.
Save zulonas/027b448451ab4719f27d70d671cf280b to your computer and use it in GitHub Desktop.
hex dump for lua
local function hex_dump(buf)
for byte=1, #buf, 16 do
local chunk = buf:sub(byte, byte + 15)
io.write(string.format('%08X ', byte - 1))
chunk:gsub('.', function (c) io.write(string.format('%02X ', string.byte(c))) end)
io.write(string.rep(' ', 3 * (16 - #chunk)))
io.write(' ', chunk:gsub('%c', '.'), "\n")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment