Using byte ordering

The following function demonstrates how to add 32-bit values originating from systems with differing byte orders. The final result is stored in the first operand. This example illustrates the proper use of integer conversion macros to ensure correct operation regardless of the host processor's native endianness.

void Add(void *OpLE, void *OpBE)
{
  UINT32 ValA, ValB;

  /* Convert values in to CPU specific format */
  ValA = stLEToCPU32(*(UINT32 *) OpLE);
  ValB = stBEToCPU32(*(UINT32 *) OpBE);

  /* Store in first argument the sum of ValA and ValB variables, */
  /* using little-endian convention */
  *(UINT32 *) OpLE = stCPUToLE32(ValA + ValB);
}
SpaceShadow documentation