I’m sending five bytes to an Arduino:
byte[] { 0xF1, byte1, byte2, byte3, 0x33 }
The values of byte1, byte2 and byte3 are dynamic. The first and last bytes are always the same.
Byte values are from 0 to 255.
How can I simply convert ints to bytes and put them into my byte array?
If you are sure that your values won’t exceed the byte range
[0, 255], you can simply cast them:In alternative you can use
Convert.ToByte, which throws anOverflowExceptionif values are less than 0 or greater than 255.