C# > System > BitConverter
Converts
- base data types to an array of bytes,
- array of bytes to base data types.
Example
Convert ushort to ASCII code.
(ascii code 2 bytes array)
ushort number = 5678;
byte[] byteArray = BitConverter.GetBytes(number);
foreach (var result in byteArray)
{
string val = System.Convert.ToChar(result).ToString();
}