endian(3) Library Functions Manual endian(3) htobe16, htole16, be16toh, le16toh, htobe32, htole32, be32toh, le32toh, htobe64, htole64, be64toh, le64toh - LIBRARY Standard C library (libc, -lc) #include uint16_t htobe16(uint16_t host_16bits); uint16_t htole16(uint16_t host_16bits); uint16_t be16toh(uint16_t big_endian_16bits); uint16_t le16toh(uint16_t little_endian_16bits); uint32_t htobe32(uint32_t host_32bits); uint32_t htole32(uint32_t host_32bits); uint32_t be32toh(uint32_t big_endian_32bits); uint32_t le32toh(uint32_t little_endian_32bits); uint64_t htobe64(uint64_t host_64bits); uint64_t htole64(uint64_t host_64bits); uint64_t be64toh(uint64_t big_endian_64bits); uint64_t le64toh(uint64_t little_endian_64bits); glibc (. feature_test_macros(7)): htobe16(), htole16(), be16toh(), le16toh(), htobe32(), htole32(), be32toh(), le32toh(), htobe64(), htole64(), be64toh(), le64toh(): glibc 2.19: _DEFAULT_SOURCE glibc 2.19 : _BSD_SOURCE / , (<< >>), (little-endian) (big-endian). nn , -- 16, 32 64 . <> . <> . <> . <> . Similar functions are present on the BSDs, where the required header file is instead of . Unfortunately, NetBSD, FreeBSD, and glibc haven't followed the original OpenBSD naming convention for these functions, whereby the nn component always appears at the end of the function name (thus, for example, in NetBSD, FreeBSD, and glibc, the equivalent of OpenBSDs "betoh32" is "be32toh"). None. glibc 2.9. byteorder(3). , be32toh() ntohl(). byteorder(3) , UNIX. , , TCP/IP , 64- , . , . , . , x86-32, : $ ./a.out x.u32 = 0x44332211 htole32(x.u32) = 0x44332211 htobe32(x.u32) = 0x11223344 #include #include #include #include int main(void) { union { uint32_t u32; uint8_t arr[4]; } x; x.arr[0] = 0x11; /* Lowest-address byte */ x.arr[1] = 0x22; x.arr[2] = 0x33; x.arr[3] = 0x44; /* Highest-address byte */ printf("x.u32 = %#x\n", x.u32); printf("htole32(x.u32) = %#x\n", htole32(x.u32)); printf("htobe32(x.u32) = %#x\n", htobe32(x.u32)); exit(EXIT_SUCCESS); } . bswap(3), byteorder(3) Azamat Hackimov , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . endian(3)