I have a device (hardware I cannot modify) that I have to communicate with data bytes. The problem I am experiencing is that I cannot simply send value converted to byte. As an example, I have value of 23, that has to be converted into the 4-byte command:
byte[0] -> MSB
byte[1] -> Mid Hi
byte[2] -> Mid Lo
byte[3] -> LSB
I cannot simply convert 25 -> 0x19 and use it like that. I am not a person who understands much of a lower-level language, I am truly trying to learn, but I know I have to shift bytes. My assumption is something like this:
int value = 23;
byte[0] = (value >> 24) & 0xFF;
byte[1] = (value >> 16) & 0xFF;
byte[2] = (value >> 8) & 0xFF;
byte[3] = value & 0xFF;
Is this correct? Will this produce outcome I am looking for? As an example how would you translate FF FF FF FB back to INT (based on the description above):
MSB: ff
Mid Hi: ff
Mid Lo:: ff
LSB: fb
What does this represent?