8-bit Memory Reverse

The 8-bit memory reverse swaps 8-bit bytes, regardless of the size of CHAR_BIT on the given platform. In order to achieve this in a platform-agnostic manner, it requires that CHAR_BIT % 8 is 0. When CHAR_BIT is larger than 8 (16, 24, 32, 64, and other values that are multiples of 8), each 8-bit byte within an unsigned char is masked off with 0xFF << (8 * byte_index), and then serialized for storing/loading. byte_index is a value from [0, CHAR_BIT / 8) and it is swapped with the reverse 8-bit byte, which is computed with 0xFF << (8 * ((CHAR_BIT / 8) - 1 - byte_index)).

void ztdc_memreverse8(size_t __n, unsigned char __ptr[ZTD_STATIC_PTR_EXTENT_I_(__n)])

Reverses each 8-bit byte in a region of memory.

Each 8-bit byte is considered according to 0xFF << multiple-of-8, where multiple-of-8 is a multiple of in the range [0, CHAR_BIT).

Remark

Constraints:

  • CHAR_BIT is a multiple of 8.

Parameters
  • __n[in] The number of bytes to reverse.

  • __ptr[in] The pointer whose 8-bit bytes will be reversed.

uintN_t ztdc_memreverse8uN(uintN_t __value)

Reverses the 8-bits of a given N-width integer type.

Remark

Equivalent to: ztdc_memreverse8(sizeof(__value), (unsigned char*)(&__value)); return __value;.

Parameters

__value[in] The exact-width integer value to be reversed.