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?
memcpy. Better, use any decent serialization library.flipping the 0 and 1, anywhere. This is how computers represent negative numbers. If you are familiar with 2-s complement arithmetic and how this translates to representing integer values, whether they are 8, 16, 32, or 64 bits, then you need to clarify, exactly, what your specific question is. If you are not familiar with these topics you can find them explained and discussed in many introductory textbooks on computer science and programming. Unfortunately, Stackoverflow is not a replacement for a textbook, we only answer specific questions here.