Endian-swap a 16-bit value in place
#include <gulliver.h> void ENDIAN_SWAP16( uint16_t * num );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The ENDIAN_SWAP16() macro endian-swaps the value pointed to by num in place.
Swap the endianness of a value:
#include <stdio.h> #include <stdlib.h> #include <gulliver.h> #include <inttypes.h> int main( void ) { uint16_t val = 0x1234; ENDIAN_SWAP16( &val ); printf( "val = 0x%04x\n", val ); return EXIT_SUCCESS; }
This prints:
val = 0x3412
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |
ENDIAN_SWAP16() is implemented as a macro.
ENDIAN_BE16(), ENDIAN_BE32(), ENDIAN_BE64(), ENDIAN_LE16(), ENDIAN_LE32(), ENDIAN_LE64(), ENDIAN_RET16(), ENDIAN_RET32(), ENDIAN_RET64(), ENDIAN_SWAP32(), ENDIAN_SWAP64(), htonl(), htons(), ntohl(), ntohs(), UNALIGNED_RET16(), UNALIGNED_RET32(), UNALIGNED_RET64(), UNALIGNED_PUT16(), UNALIGNED_PUT32(), UNALIGNED_PUT64()