Posted 28 March 2013 - 02:54 PM
Just a simple function to convert an unsigned byte into its bit pattern. Give it a number from 0-255 and it will give you a binary sequence for that number.
You can use string.byte() with a UTF-8 compatible character to get its byte.
Also included an extremely simple reconversion function for convenience.
It's really small at 9 lines, but here is a pastebin if that is too hard for you. pastebin get h4aa5CWr
Now you can have fun with saving and reading binary from files. Even tighter data compression!
You can use string.byte() with a UTF-8 compatible character to get its byte.
Also included an extremely simple reconversion function for convenience.
function dec2Bin(dec)
dec=dec*2
local bin=""
for i=0,7 do
bin=bin..tostring(math.ceil(math.floor(dec/2)%2))
dec=math.floor(dec/2)
end
return string.reverse(bin)
end
function bin2Dec(bin)
return tonumber(bin, 2)
end
It's really small at 9 lines, but here is a pastebin if that is too hard for you. pastebin get h4aa5CWr
Now you can have fun with saving and reading binary from files. Even tighter data compression!