Tuesday, June 29, 2010

Binary to String Conversion in C#

Converting binary to different format is quiet common scenario for developers.Its just two line of code that will do the magic , but when time matter love search in google so if this blog help someone really happy for that.
Binary to String

System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string str = enc.GetString(MyByteArray);
if you want to make sure that there is no data loss then use Base64 Encoding

Base64 Encoding :- converts binary data to plain text using 64 case-sensitive, printable ASCII characters: A-Z, a-z, 0-9, plus sign (+) and forward slash (/), and may be terminated with 0-2 "padding" characters represented by the equal sign (=).

Convert.ToBase64String(myByteArray);
when you are working with picture it will be good to use Base64 conversion so you could make sure that there is no data lose

1 comment: