大小端转换的函数

static inline void endian_swap(void* data, int size)
{
    UHAL_ASSERT((size == 2) ||
                (size == 4) ||
                (size == 8), "no size");
    uint8_t* bdata = (uint8_t*)data;

    for (int x = 0; x < size/2; ++x) {
        uint8_t temp = bdata[x];
        bdata[x] = bdata[size-x-1];
        bdata[size-x-1] = temp;
    }
}

你可能感兴趣的:(C语言)