21 lines
422 B
Lua
21 lines
422 B
Lua
--- Binary data utilities
|
|
module ("bin", package.seeall)
|
|
|
|
--- Turn a little-endian word into a number
|
|
function le_to_number (s)
|
|
local res = 0
|
|
for i = #s, 1, -1 do
|
|
res = res * 256 + string.byte (s, i)
|
|
end
|
|
return res
|
|
end
|
|
|
|
--- Turn a little-endian word into a hex string
|
|
function le_to_hex (s)
|
|
local res = ""
|
|
for i = 1, #s do
|
|
res = res .. string.format ("%.2x", string.byte (s, i))
|
|
end
|
|
return res
|
|
end
|