Rate This Document
Findability
Accuracy
Completeness
Readability

SwapBytes

Reverses the byte order of data. This function can be used for big-endian and little-endian data conversion.

The function interface declaration is as follows:

Operations on integers:

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

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the source vector

The value cannot be NULL.

Input

dst

Pointer to the destination vector

The value cannot be NULL.

Output

srcDst

Pointer to the source vector for in-place operations

The value cannot be NULL.

Input/Output

len

Vector length

(0, INT_MAX]

Input

Return Value

  • Success: HMPP_STS_NO_ERR
  • Failure: An error code is returned.

Error Codes

Error Code

Description

HMPP_STS_NULL_PTR_ERR

Any of the specified pointers is NULL.

HMPP_STS_SIZE_ERR

The value of len is less than or equal to 0.

Example

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

Output:

HMPPS_SwapBytes_16u result = 0
len = 8
dst = 865092540 4294967295 676259188 241112424 316591459 0 3452617907 1844768311