Safwanrockz

Binary to Decimal

Feb 1st, 2014
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.31 KB | None | 0 0
  1. function Bin2Dec(s)
  2.      local num = 0
  3.      local ex = string.len(s) - 1
  4.      local l = 0
  5.      l = ex + 1
  6.      for i = 1, l do
  7.           b = string.sub(s, i, i)
  8.           if b == "1" then
  9.                num = num + 2^ex
  10.           end
  11.           ex = ex - 1
  12.      end
  13.      return string.format("%u", num)
  14. end
Advertisement
Add Comment
Please, Sign In to add comment