1 .\" Copyright (C) 2016 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH BSWAP 3 2021-06-20 "Linux man-pages (unreleased)"
7 bswap_16, bswap_32, bswap_64 \- reverse order of bytes
10 .RI ( libc ", " \-lc )
13 .B #include <byteswap.h>
15 .BI "uint16_t bswap_16(uint16_t " x );
16 .BI "uint32_t bswap_32(uint32_t " x );
17 .BI "uint64_t bswap_64(uint64_t " x );
20 These functions return a value in which the order of the bytes
21 in their 2-, 4-, or 8-byte arguments is reversed.
23 These functions return the value of their argument with the bytes reversed.
25 These functions always succeed.
27 These functions are GNU extensions.
29 The program below swaps the bytes of the 8-byte integer supplied as
30 its command-line argument.
31 The following shell session demonstrates the use of the program:
35 $ \fB./a.out 0x0123456789abcdef\fP
36 0x123456789abcdef ==> 0xefcdab8967452301
49 main(int argc, char *argv[])
54 fprintf(stderr, "Usage: %s <num>\en", argv[0]);
58 x = strtoull(argv[1], NULL, 0);
59 printf("%#" PRIx64 " ==> %#" PRIx64 "\en", x, bswap_64(x));