Reputation: 21
I'm working with the language Lua, and I have a long string of binary numbers, which I'd like to put into an array with each digit as its own element within the array.
Upvotes: 2
Views: 278
Reputation: 5788
local str, out = "01101101010010010", {}
for i = 1, #str do
out[#out+1] = string.sub(str,i,i)
end
Change line 3 to out[#out+1] = tonumber(string.sub(str,i,i))
if you want the array to contain numbers rather than strings.
Upvotes: 3