I am currently sending an array of unsigned, 8 bit integers to a C program through Bluetooth (as a characteristic). When this packet is received, I want to take a pair of the indexes and "concatenate" their numbers, like so:
Input: [0xDE, 0xAD,
0xDE, 0xAD,
0xBE, 0xEF]
Output: [0xDEAD, 0xDEAD, 0xBEEF]
However, I am running into a strange issue. My code works fine when I output to an even index (Taking the first two elements of the array and concatinating them), but fails when I output to an odd element (For example, trying to concatinate elements 3 and 4 (0xDE and 0xAD).
So, my output that I am getting from the program is this:
Input: [0xDE, 0xAD,
0xDE, 0xAD,
0xBE, 0xEF]
Output: [0xDEAD, 0xADDE, 0xBEEF]
Here is my code:
for(int i = 0; i < numUUID; i++)
{
// The i+1 and i+2 are because the first value of the array contains
// a byte on how many UUIDs are incoming
uuidFilter[i] = (incoming[i + 1] << 8) | incoming[i + 2];
}