Created
April 10, 2022 01:58
-
-
Save mtso/048b868e143f498fbf14010831a526c3 to your computer and use it in GitHub Desktop.
pico-8 serialization / deserialization for bit-packing cartdata
This file contains 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 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