Created
February 3, 2019 11:36
-
-
Save daurnimator/97b0eb63863e34fb25fe77d2fe090ec5 to your computer and use it in GitHub Desktop.
lua function for showing binary representation of a string
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
local function tobin(x) | |
local t = {} | |
for i=0,#x-1 do | |
local c = x:byte(i+1) | |
for j=0,7 do | |
t[i*8+j+1] = (c & 0x80) ~= 0 and "1" or "0" | |
c = c << 1 | |
end | |
end | |
return table.concat(t) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment