The portable way to manipulate raw byte arrays is std::memcpy
and char
buffers.
uint32_t toBeSent = 42;
char buffer[sizeof toBeSent];
std::memcpy(&buffer, &toBeSent, sizeof toBeSent);
sendBuffer(buffer);
// ...
uint32_t toBeReceived;
char buffer[sizeof toBeReceived];
receiveBuffer(buffer);
std::memcpy(&toBeReceived, &buffer, sizeof toBeReceived);
4
solved How to store uint32_ts in an array of uint8_ts