Skip to content

Instantly share code, notes, and snippets.

@mrogaski
Last active August 29, 2015 14:04
Show Gist options
  • Save mrogaski/3272d0c0d15b027afb01 to your computer and use it in GitHub Desktop.
Save mrogaski/3272d0c0d15b027afb01 to your computer and use it in GitHub Desktop.
Bytewise increment function in Lua
b = { 0, 0, 0, 0, 0, 0, 0, 0 }
function byte_inc(b)
local c = 1
for i = 1, 8 do
local new = (b[i] + c) % 0xFF
c = math.floor((b[i] + c) / 0xFF)
b[i] = new
if c == 0 then
break
end
end
return b
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment