C++ - 大端转小端函数

 

用于多字节的大端转小端

//大端转小端
void endianSwap(uint8_t *pData, int startIndex, int length) {
    int i, cnt, end, start;
    cnt = length / 2;
    start = startIndex;
    end  = startIndex + length - 1;
    uint8_t tmp;
    for (i = 0; i < cnt; i++) {
        tmp            = pData[start + i];
        pData[start + i] = pData[end - i];
        pData[end - i]   = tmp;
    }
}
void use_endianSwap(uint8_t *pData) {
    for (int i = 0; i < 4; i += 4) {
        endianSwap(pData, i, 4);
    }
}

 

posted @ 2020-10-26 15:27  Citrusliu  阅读(2211)  评论(0编辑  收藏  举报