SwapBytes
反转数据字节顺序。可用于大小端数据的转换。
函数接口声明如下:
整型数的操作:
HmppResult HMPPS_SwapBytes_16u(const uint16_t *src, uint16_t *dst, int32_t len);
HmppResult HMPPS_SwapBytes_24u(const uint8_t *src, uint8_t *dst, int32_t len);
HmppResult HMPPS_SwapBytes_32u(const uint32_t *src, uint32_t *dst, int32_t len);
HmppResult HMPPS_SwapBytes_64u(const uint64_t *src, uint64_t *dst, int32_t len);
HmppResult HMPPS_SwapBytes_16u_I(uint16_t *srcDst, int32_t len);
HmppResult HMPPS_SwapBytes_24u_I(uint8_t *srcDst, int32_t len);
HmppResult HMPPS_SwapBytes_32u_I(uint32_t *srcDst, int32_t len);
HmppResult HMPPS_SwapBytes_64u_I(uint64_t *srcDst, int32_t len);
参数
参数名  | 
描述  | 
取值范围  | 
输入/输出  | 
|---|---|---|---|
src  | 
指向源向量的指针。  | 
非空  | 
输入  | 
dst  | 
指向目的向量的指针。  | 
非空  | 
输出  | 
srcDst  | 
指向原址操作向量的指针。  | 
非空  | 
输入/输出  | 
len  | 
向量长度。  | 
(0,INT_MAX]  | 
输入  | 
返回值
- 成功:返回HMPP_STS_NO_ERR。
 - 失败:返回错误码。
 
错误码
错误码  | 
描述  | 
|---|---|
HMPP_STS_NULL_PTR_ERR  | 
当任何指定的指针为空时指示错误。  | 
HMPP_STS_SIZE_ERR  | 
len小于或等于0。  | 
示例
#define SRC_LEN 8
void SwapBytesExample(void)
{
    int32_t len = SRC_LEN;
    uint32_t src[SRC_LEN] = { 3158544435, 4294967295, 1961184808, 1746231054, 1674436114, 0, 3016018637, 938407021 };
    uint32_t dst[SRC_LEN] = { 0 };
    HmppResult result = HMPPS_SwapBytes_32u(src, dst, len);
    printf("HMPPS_SwapBytes_16u result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    int32_t i;
    printf("len = %d\ndst =", len);
    for(i = 0; i < len; ++i){
        printf(" %u", dst[i]);
    }
    printf("\n");
}
运行结果:
HMPPS_SwapBytes_16u result = 0 len = 8 dst = 865092540 4294967295 676259188 241112424 316591459 0 3452617907 1844768311