RED HAT
RED HAT
DIIDevHeads IoT Integration Server
Created by electro_coco on 8/16/2024 in #code-review
How can I recover binary data from the INTDATA file using the provided C structure?
For instance if you detect that the data is in big-endian format and needs to be converted to little-endian (or vice versa), you’ll have to perform byte swapping to convert a 16-bit or 32-bit value from big-endian to little-endian, using this approach
uint16_t swap_uint16(uint16_t val) {
return (val << 8) | (val >> 8);
}

uint32_t swap_uint32(uint32_t val) {
return ((val << 24) & 0xFF000000) |
((val << 8) & 0x00FF0000) |
((val >> 8) & 0x0000FF00) |
((val >> 24) & 0x000000FF);
}
uint16_t swap_uint16(uint16_t val) {
return (val << 8) | (val >> 8);
}

uint32_t swap_uint32(uint32_t val) {
return ((val << 24) & 0xFF000000) |
((val << 8) & 0x00FF0000) |
((val >> 8) & 0x0000FF00) |
((val >> 24) & 0x000000FF);
}
10 replies