我正在玩 Feed The Beast 并想创建一个网络。我已经可以将二进制代码从一台计算机发送到另一台计算机。从字符串中获取二进制代码的方法如下:
function toBinString(s)
bytes = {string.byte(s,i,string.len(s))}
binary = ""
for i,number in ipairs(bytes) do
c = 0
while(number>0) do
binary = (number%2)..binary
number = number - (number%2)
number = number/2
c = c+1
end
while(c<8) do
binary = "0"..binary
c = c+1
end
end
return binary
end
function toBin(s)
binary = toBinString(s)
ret = {}
c = 1
for i=1,string.len(binary) do
char = string.sub(binary,i,i)
if(tonumber(char)==0) then
ret[c] = 0
c = c+1
elseif(tonumber(char)==1) then
ret[c] = 1
c = c+1
elseif(tonumber(char)) then
print("Error: expected \'0\' or \'1\' but got \'",char,"\'.")
end
end
return ret
end
我怎样才能得到使用的字符串string.byte(...)
?