Mega Code Archive

 
Categories / C# / Development Class
 

Convert 16-bit signed integer value to an array of bytes

using System; class GetBytesInt16Demo {     const string formatter = "{0,10}{1,13}";     public static void GetBytesInt16( short argument )     {         byte[ ] byteArray = BitConverter.GetBytes( argument );         Console.WriteLine( formatter, argument, BitConverter.ToString( byteArray ) );     }     public static void Main( )     {         GetBytesInt16( 0 );         GetBytesInt16( 15 );     } }