编程语言
首页 > 编程语言> > C++ - 大端转小端函数

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);
    }
}

 

标签:tmp,end,int,转小端,C++,pData,start,大端
来源: https://www.cnblogs.com/citrus/p/13878718.html