HighByte and LowByte

I have an integer (1500). I have found its highByte and LowByte below and sent it from a Photon to another one using the code below.

//NUMBER = 1500 : LB = 220 HB = 5
byte high = highByte(1500);   // = 5
byte low = lowByte(1500);      // = 220

I am receiving the byte array on the other board correctly. What is the code for reconstituting the original value (1500)?

Thanks in advance for the help.

highByte * 256 + lowByte

(5 * 256 + 220) = 1500

@Jimmie, and “integer” in Particle devices is expressed as a 4 byte/ 32bit value as opposed to the typical Arduino 2 byte / 16bit representation. For you highByte/lowByte to work, you will need to define a 16bit integer or using int16_t or short int. The target board needs to have the same representation. Then, to reconstitute your integer, you simply need to reconstruct the high and low bytes with:

short int value = highByte << 8 + lowByte;   // the <<8 is a bit shift which is the same as a multiply by 256
3 Likes