endian.h File Reference

Convert values between host and big-/little-endian byte order. More...

#include <stdint.h>

Macros

#define be32toh(big_endian_32bits)
 Transform big endian uint32_t to host uint32_t. More...
 
#define htobe32(host_32bits)
 Transform host uint32_t to big endian uint32_t. More...
 

Detailed Description

Convert values between host and big-/little-endian byte order.

Macro Definition Documentation

◆ be32toh

#define be32toh (   big_endian_32bits)
Value:
((uint32_t)(((((unsigned char*)&(big_endian_32bits))[0]) << 24) + \
((((unsigned char*)&(big_endian_32bits))[1]) << 16) + \
((((unsigned char*)&(big_endian_32bits))[2]) << 8) + \
(((unsigned char*)&(big_endian_32bits))[3])))

Transform big endian uint32_t to host uint32_t.

◆ htobe32

#define htobe32 (   host_32bits)
Value:
(uint32_t)(((((uint32_t)(host_32bits)) & 0xFF) << 24) | \
((((uint32_t)(host_32bits)) & 0xFF00) << 8) | \
((((uint32_t)(host_32bits)) & 0xFF0000) >> 8) | \
((((uint32_t)(host_32bits)) & 0xFF000000) >> 24))

Transform host uint32_t to big endian uint32_t.