-1

how to convert bytes to string, i am using below code to convert string to bytes. i want code to convert that bytes to string.

public byte[] FileToByteArray(string fileName)
{
    byte[] buff = null;
    FileStream fs = new FileStream(fileName,
                                   FileMode.Open,
                                   FileAccess.Read);
    BinaryReader br = new BinaryReader(fs);
    long numBytes = new FileInfo(fileName).Length;
    //buff = br.ReadBytes((int)numBytes);
    buff = br.ReadBytes(16);
    return buff;
}
trm nhcl
  • 17
  • 4

1 Answers1

2
string result = System.Text.Encoding.UTF8.GetString(byteArray);

also a quicker way to convert a string to byte array

byte[] MyByteArray = str.Select(s => Byte.Parse(s)).ToArray();
Eminem
  • 7,206
  • 15
  • 53
  • 95