Search code examples
c#asciistreamreader

Convert file (or byte[]) into ascii, then convert that ascii back into the original file


I'm using an old technology called RTTY to send data (it's basically fancy Morse Code) over radio.

RTTY can only transmit ascii characters

What I want to do is convert a file such as a small jpg or something similar into a block of ascii text, send the characters over radio, then convert the characters on the remote end back into the original file.

Some help getting started would be great.

I know I need to use StreamReader but then how can I convert the byte[] into an encoded ascii string that I can then 'decode'.


Solution

  • I know i need to use streamreader but then how can I convert the byte[] into an encoded ascii string that I can then 'decode'

    Basically, you want to use a Base64 conversion. It will inflate the size of the data, but it guarantees that you'll be able to round-trip the original binary data.

    Use Convert.ToBase64String to convert a byte[] into a string, and Convert.FromBase64String to do the reverse.