Convert two bytes at a specified position in a byte array to a Unicode character : BitConverter « Development Class « C# / C Sharp






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 );
    }
}

   
  








Related examples in the same category

1.Convert byte array to String with BitConverter
2.Convert byte array to Int32
3.BitConverter converts base data types to an array of bytes, and an array of bytes to base data types.
4.Convert bytes to UInt32.
5.Convert various data type to string with BitConverter
6.Converts double number to a 64-bit signed integer.
7.Convert Boolean value to an array of bytes.
8.Convert Unicode character to an array of bytes.
9.Convert double to an array of bytes.
10.Convert 16-bit signed integer value to an array of bytes.
11.Convert 32-bit signed integer value to an array of bytes.
12.Convert 64-bit signed integer value to an array of bytes.
13.Convert single-precision floating point value to an array of bytes.
14.Convert specified 16-bit unsigned integer value to an array of bytes.
15.Convert specified 32-bit unsigned integer value to an array of bytes.
16.Convert specified 64-bit unsigned integer value to an array of bytes.
17.Converts 64-bit signed integer to a double-precision floating point number.
18.Indicates the byte order ("endianness")
19.Convert one byte at a specified position in a byte array to bool
20.Convert two bytes at a specified position in a byte array to a 16-bit signed integer
21.Convert four bytes at a specified position in a byte array to a 32-bit signed integer