Mega Code Archive

 
Categories / C# / Development Class
 

Convert two bytes at a specified position in a byte array to a Unicode character

using System; class BytesToCharDemo {     const string formatter = "{0,5}{1,17}{2,8}";     public static void BAToChar( byte[] bytes, int index )     {         char value = BitConverter.ToChar( bytes, index );         Console.WriteLine( formatter, index, BitConverter.ToString( bytes, index, 2 ), value );     }     public static void Main( )     {         byte[] byteArray = {32,   10,   10,  42,   10,  65,   10, 125,   10,              197,   10, 168,   3,  41,   4, 172,  32 };         Console.WriteLine( BitConverter.ToString( byteArray ) );         BAToChar( byteArray, 0 );     } }