Using BitConverter.GetBytes , you will convert your integer into a byte[] array using the internal system entity.
short s = 2200; byte[] b = BitConverter.GetBytes(s); Console.WriteLine(b[0].ToString("X")); // 98 (on my current system) Console.WriteLine(b[1].ToString("X")); // 08 (on my current system)
If you need explicit control over the conversion content, you need to do this manually:
short s = 2200; byte[] b = new byte[] { (byte)(s >> 8), (byte)s }; Console.WriteLine(b[0].ToString("X"));
Lukeh
source share