How to store negative number in a uint_8 array

75 views Asked by At

I am trying to send some data with BLE from an STM32 board to an Raspberry Pi 3B board. However, the "write" function of BLE API only supports uint8_t array transfer, but the data I need to send include both positive and negative numbers such as 42 and -283. The original values are stored in an int16_t variable, and I need to parse them into the uint8_t array before transfer them. I just want one int16_t be put in an array, so it can take use more that one slot in the array if needed. For example, 283 can be stored as 1,1B.

Does anyone know how to do that? I guess I can use >>8 to do it, but how about the negative numbers?

0

There are 0 answers