Advertisement
BobMe

binary to integer yes

Dec 13th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. -- binary to interger yes?
  2.  
  3. number = "1010011010"
  4.  
  5. countup = 0
  6.  
  7. function removedeci(x)
  8. local y = tostring(x)
  9. for i=1,#y do
  10. if string.sub(y,i,i+1) == ".0" then
  11. return tonumber(string.sub(y,1,i-1))
  12. end
  13. end
  14. return(x)
  15. end
  16.  
  17. for i=1,#number do
  18. if string.sub(number,i,i) == "1" then
  19. countup = countup+2^((#number-i))
  20. end
  21. end
  22.  
  23. print(#number.." bit, "..removedeci(countup))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement