How do I convert separate int values to hex byte array

Viewed 2439

I need to do some (new to me) int/hex/byte work and I am struggling to get it right. The tcp server on the other side is expecting Little Endian.

I need to send a byte array consisting of HEX values.

6000 needs to be sent as:

0x70, 0x17

19 needs to be sent as:

0x13, 0x00, 0x00, 0x00

parameters

The resulting byte array should look like this.

**FROM THE MANUFACTURER**
Complete message should be: 

0x70, 0x17, 0x13, 0x00, 0x00, 0x00, 0x40, 0x42, 0x0f, 0x00, 0xA0, 0x86, 0x01, 0x00, 0x04, 0x01, 0x02, 0x03, 0x04

I can get the hex value of 6000 as 1770 by using: .ToString("x4") I can get the hex value of 19 as 00000013 by using: .ToString("x8")

I have two questions:

  1. This (to my knowledge) is Big Endian. Short from chopping the string and manually rewriting it to reverse it, is there a .net routine that can do this for me?

  2. Once I have it reversed, how do I get

7017

in a byte array of:

[0] = 0x70, [1] = 0x17

Thanks in advance.

1 Answers
Related