Posted 08 September 2013 - 08:09 PM
I am trying to make a binary decoder in which you would enter a number in binary, and you would get that number back in decimal, though for some reason no matter what I enter, it returns 0.
> pastebin get RjedXHpP binary
Thanks in advance.
term.clear()
term.setCursorPos(1,2)
write("Binary number: ")
local binary = io.read()
local function getDecimal(place,code)
local a = 1
for i = 1,place do
local a = a*2
print(a)
end
if string.sub(code,a,a) == "1" then
return a
else
return 0
end
end
local b = 0
for i=1,#binary do
local b = b + getDecimal(i,binary)
end
term.clear()
term.setCursorPos(1,1)
print("")
print(binary.." in decimal is "..B)/>
or you can do> pastebin get RjedXHpP binary
Thanks in advance.