HTOBE64(3)

NAME
htobe64, htobe32, htobe16, be64toh, be32toh, be16toh, betoh64, betoh32, betoh16, htole64, htole32, htole16, le64toh, le32toh, le16toh, letoh64, letoh32, letoh16, swap64, swap32, swap16 - convert values between different byte orderings

SYNOPSIS
#include <endian.h>
uint64_t
htobe64(uint64_t host64);
uint32_t
htobe32(uint32_t host32);
uint16_t
htobe16(uint16_t host16);
uint64_t
be64toh(uint64_t big64);
uint32_t
be32toh(uint32_t big32);
uint16_t
be16toh(uint16_t big16);
uint64_t
betoh64(uint64_t big64);
uint32_t
betoh32(uint32_t big32);
uint16_t
betoh16(uint16_t big16);
uint64_t
htole64(uint64_t host64);
uint32_t
htole32(uint32_t host32);
uint16_t
htole16(uint16_t host16);
uint64_t
letoh64(uint64_t little64);
uint64_t
le64toh(uint64_t little64);
uint32_t
le32toh(uint32_t little32);
uint16_t
le16toh(uint16_t little16);
uint32_t
letoh32(uint32_t little32);
uint16_t
letoh16(uint16_t little16);
uint64_t
swap64(uint64_t val64);
uint32_t
swap32(uint32_t val32);
uint16_t
swap16(uint16_t val16);

DESCRIPTION
These routines convert 16, 32 and 64-bit quantities between different byte orderings. The “swap” functions reverse the byte ordering of the given quantity; the others convert either from/to the native byte order used by the host to/from either little- or big-endian (a.k.a network) order.

Apart from the swap functions, the names containing “be” convert between host and big-endian (most significant byte first) order of the given quantity, while the names containing “le” convert between host and little-endian (least significant byte first) order of the given quantity.

All these functions use the numbers 16, 32, or 64 for specifying the bitwidth of the quantities they operate on. Currently all supported architectures are either big- or little-endian so either the “be” or “le” variants are implemented as null macros.

SEE ALSO
htonl(3)

STANDARDS
The htobe64(), htobe32(), htobe16(), be64toh(), be32toh(), be16toh(), htole64(), htole32(), htole16(), le64toh(), le32toh(), and le16toh() functions are expected to conform to a future version of p1003.1. The other functions are extensions that should not be used when portability is required.

HISTORY
The swap{size} and {src-order}to{dst-order}{size} functions appeared in 4.2BSD. The {src-order}{size}to{dst-order} functions appeared in OpenBSD 5.6. A subset of them was submitted for standardization after p1003.1-2008.

BUGS
The perceived antagonism between ‘host’ and ‘network’ byte order does not allow PDP-11 users to sleep soundly at night.