If you want to do this conversion, just delete the top byte of the four-byte number. The two-component representation will take care of the sign correctly. If you want to store a 24-bit number in a variable Int32, you can use v & 0xFFFFFFto get only the lower 24 bits. I saw your comment about a byte array: if you have space in the array, write all four bytes of the number and just send the first three; which is typical for small systems.
source
share