Converting string value to binary and vice versa

I’m having some real trouble with this. I’ve not got any code down, but what I want to do is this: convert strings to binary, and be able to decode that binary into a string. I can’t find anything on string.format here, and string.byte doesn’t cut the mustard.
Anything I can do here? I can find nothing on this.

Can’t you loop through all indexes in the string, and use string.byte on each letter? Afaik, this is the only way, not that I’ve ever used it though.

You could do a byte by byte translation using simple math.

Tried, problem is when you concatenate the numbers it’s hard to translate them back without knowing the original code.

Could you please explain this in greater detail?

A string is a byte array so each letter is 8 bits, or 8 ones/zeros. Just convert each letter in the string to it’s ASCII number then to binary then add zeros to the front to ensure it’s 8 numbers long, and add them to the end of the binary string, going from left to right. To decode split the binary string into 8 character parts and convert each of the bytes back into their respective ASCII codes then back into characters, piecing them onto a string

[editline]20th June 2011[/editline]

Also, ironically, the only way to have something as “binary” in lua is in another string, making your string take up 8 times as much space as it did before. Also, the string you are converting is already in binary form inside the computer as that’s what the processor uses. It can’t read.

OH! That’s a genius idea! I just thought of writing up a custom table to do it all but your method seems to fit the bill exactly. Thanks!