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
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:
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?
Once I have it reversed, how do I get
7017
in a byte array of:
[0] = 0x70, [1] = 0x17
Thanks in advance.

byte[] {0x70, 0x17}?BitConverter.GetBytes(value);would by more suitable than strings. And once you have a byte array, just callArray.Reverse(bytes);to reverse your bytes.0x70, 0x17, 0x13, 0x00, 0x00, 0x00, 0x40, 0x42, 0x0f, 0x00, 0xA0, 0x86, 0x01, 0x00, 0x04, 0x01, 0x02, 0x03, 0x040x70, 0x17etc is just human-readable form of the bytes, but the bytes "on the wire" take 1 byte per byte, instead of 4 (0x17 is 23 etc.) If you really format them and send a string separated by commas, use the code of Mong Zhu below.