Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function numberString(number)
- local s = ""
- repeat
- local remainder = number % 2
- s = remainder..s
- number = (number-remainder)/2
- until number==0
- return s
- end
- function fromBinary(str)
- if #str % 8 ~= 0 then
- error("Malformed Binary Sequence",2)
- end
- local result = ""
- for i = 1, #str, 8 do
- result = result..string.char(tonumber(str:sub(i,i+7),2))
- end
- return result
- end
- function toBinary(str)
- if #str > 0 then
- local result = ""
- for a = 1, #str do
- result = result..string.format("%08d",numberString(string.byte(string.sub(str,a,a))))
- end
- return result
- else return nil
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment