bswap16, bswap32, bswap64, be16toh, be32toh, be64toh, htobe16, htobe32, htobe64, htole16, htole32,
Contents
Description
The bswap16(), bswap32(), and bswap64() functions return a byte order swapped integer. On big endian
systems, the number is converted to little endian byte order. On little endian systems, the number is
converted to big endian byte order.
The be16toh(), be32toh(), and be64toh() functions return a big endian byte ordered integer converted to
the system's native byte order. The return value will be the same as the argument on big endian systems.
The le16toh(), le32toh(), and le64toh() functions return a little endian byte ordered integer converted
to the system's native byte order. The return value will be the same as the argument on little endian
systems.
The htobe16(), htobe32(), and htobe64() functions return an integer in the system's native byte order
converted to big endian byte order. The return value will be the same as the argument on big endian
systems.
The htole16(), htole32(), and htole64() functions return a integer in the system's native byte order
converted to little endian byte order. The return value will be the same as the argument on little
endian systems.
The be16enc(), be16dec(), be32enc(), be32dec(), be64enc(), be64dec(), le16enc(), le16dec(), le32enc(),
le32dec(), le64enc(), and le64dec() functions encode and decode integers to/from byte strings on any
alignment in big/little endian format.
History
The hto*() and *toh() functions first appeared in FreeBSD 5.0, and were originally developed by the
NetBSD project.
The encode/decode functions first appeared in FreeBSD 5.1.
Debian April 29, 2002 BYTEORDER(9)
Name
bswap16, bswap32, bswap64, be16toh, be32toh, be64toh, htobe16, htobe32, htobe64, htole16, htole32,
htole64, le16toh, le32toh, le64toh, be16enc, be16dec, be32enc, be32dec, be64enc, be64dec, le16enc,
le16dec, le32enc, le32dec, le64enc, le64dec — byte order operations
See Also
byteorder(3)
Synopsis
#include<sys/endian.h>uint16_tbswap16(uint16_tint16);
uint32_tbswap32(uint32_tint32);
uint64_tbswap64(uint64_tint64);
uint16_tbe16toh(uint16_tbig16);
uint32_tbe32toh(uint32_tbig32);
uint64_tbe64toh(uint64_tbig64);
uint16_thtobe16(uint16_thost16);
uint32_thtobe32(uint32_thost32);
uint64_thtobe64(uint64_thost64);
uint16_thtole16(uint16_thost16);
uint32_thtole32(uint32_thost32);
uint64_thtole64(uint64_thost64);
uint16_tle16toh(uint16_tlittle16);
uint32_tle32toh(uint32_tlittle32);
uint64_tle64toh(uint64_tlittle64);
uint16_tbe16dec(constvoid*);
uint32_tbe32dec(constvoid*);
uint64_tbe64dec(constvoid*);
uint16_tle16dec(constvoid*);
uint32_tle32dec(constvoid*);
uint64_tle64dec(constvoid*);
voidbe16enc(void*, uint16_t);
voidbe32enc(void*, uint32_t);
voidbe64enc(void*, uint64_t);
voidle16enc(void*, uint16_t);
voidle32enc(void*, uint32_t);
voidle64enc(void*, uint64_t);
