Created
January 5, 2017 08:26
-
-
Save xiaobin83/1682dae4ca6e95a5ca4fc47cc8db3d31 to your computer and use it in GitHub Desktop.
Lua HexDump from http://lua-users.org/wiki/HexDump
This file contains hidden or 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
function HexDump(buf) | |
local s = {} | |
s.output = '' | |
for byte=1, #buf, 16 do | |
local chunk = buf:sub(byte, byte+15) | |
s.output = s.output .. string.format('%08X ',byte-1) | |
chunk:gsub('.', function (c) s.output = s.output .. string.format('%02X ',string.byte(c)) end) | |
s.output = s.output .. string.rep(' ',3*(16-#chunk)) | |
s.output = s.output .. chunk:gsub('%c','.') .. "\n" | |
end | |
return s.output | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment