16 bits integer in an array of 8 bits integers

Hi,
I'm trying to send the value of a sensor by LoRa communication. My problem is that in all my functions, the message that i have to send is in an array of 8 bits integers (characters), whereas the value of my sensor measure is a 16 bits int.

Here's how i crate my buffer that i have to send

uint8_t buff[2] = {0};

I'm searching a way to send my whole value in separate 8 bits integers

Thanks !

The easiest way to split the 16 bits into 2 bytes is to use the highByte() and lowByte() functions

1 Like

The Lora API expects a pointer on the first byte of a buffer and the length of this buffer

If you have only one reading like a 2 byte int, just pass the address of that int (cast to byte/char pointer as per the expected API) and 2 for the size (or sizeof variable)

If you have multiple ints get them in an array (the language guarantees that they are in consecutive bytes in memory) and pass as pointer the name of the array, cast a uint8_t*, and sizeof your array for the number of bytes

Don’t make your life hard by trying to go the other way

I tried to use the highByte() and lowByte() functions and it worked, thanks so much !

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.