BitConverter question

  • Thread starter Thread starter Timothy V
  • Start date Start date
T

Timothy V

Hi,
I have a byte[] that i want to convert into a string. I use the
BitConverter.ToString() method.

Now, how do I convert that string back into a byte[]?

Thanks in advance,

Tim.
 
Use Base64 instead. BitConverter.ToString(bytes) is just simple way to
formatted hex string from byte array.
byte[] myBytes = new byte[]{1,2,3};
string b64 = Convert.ToBase64String(myBytes);
Console.WriteLine(b64);
// Convert back to bytes.
byte[] myBytes2 = Convert.FromBase64String(b64);
Console.WriteLine("myBytes.Length:"+myBytes2.Length);
 
You can use System.Text.Encoding.Default.GetBytes and
System.Text.Encoding.Default.GetString.
 
Back
Top