Skip to content

Instantly share code, notes, and snippets.

@daurnimator
Created February 3, 2019 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daurnimator/97b0eb63863e34fb25fe77d2fe090ec5 to your computer and use it in GitHub Desktop.
Save daurnimator/97b0eb63863e34fb25fe77d2fe090ec5 to your computer and use it in GitHub Desktop.
lua function for showing binary representation of a string
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