Skip to content

Instantly share code, notes, and snippets.

@mtso
Created April 10, 2022 01:58
Show Gist options
  • Save mtso/048b868e143f498fbf14010831a526c3 to your computer and use it in GitHub Desktop.
Save mtso/048b868e143f498fbf14010831a526c3 to your computer and use it in GitHub Desktop.
pico-8 serialization / deserialization for bit-packing cartdata
function ser(n1,n2,n3,n4)
return (n1&0xff)<<8 | n2&0xff |
(n3&0xff)>>8 | (n4&0xff)>>16
end
function deser(n)
return {
(n>>8) & 0xff,
n&0xff,
(n<<8) & 0xff,
(n<<16) & 0xff
}
end
-- Usage:
-- cartdata(id)
-- local n = ser(0, 255, 128, 0)
-- dset(0, n)
-- local np = deser(dget(0))
-- print(np[2]) // 255
-- print(np[3]) // 128
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment