Skip to content

Instantly share code, notes, and snippets.

@echohes
Created August 22, 2022 10:08
Show Gist options
  • Save echohes/a691d32b4ac3bbaf98a1c61a6effad7a to your computer and use it in GitHub Desktop.
Save echohes/a691d32b4ac3bbaf98a1c61a6effad7a to your computer and use it in GitHub Desktop.
Convert binary to int
--a binary number is represented as values in a table
t_bin = {1,0,0,0,0,0,0,0}
function bin_to_in(x)
r=0
for k,v in pairs(x) do
r = r + (v*2^(8-k))
end
return math.floor(r)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment