1 .\" Copyright (C) 2016 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH BSWAP 3 2021-06-20 "Linux" "Linux Programmer's Manual"
27 bswap_16, bswap_32, bswap_64 \- reverse order of bytes
30 .B #include <byteswap.h>
32 .BI "uint16_t bswap_16(uint16_t " x );
33 .BI "uint32_t bswap_32(uint32_t " x );
34 .BI "uint64_t bswap_64(uint64_t " x );
37 These functions return a value in which the order of the bytes
38 in their 2-, 4-, or 8-byte arguments is reversed.
40 These functions return the value of their argument with the bytes reversed.
42 These functions always succeed.
44 These functions are GNU extensions.
46 The program below swaps the bytes of the 8-byte integer supplied as
47 its command-line argument.
48 The following shell session demonstrates the use of the program:
52 $ \fB./a.out 0x0123456789abcdef\fP
53 0x123456789abcdef ==> 0xefcdab8967452301
66 main(int argc, char *argv[])
71 fprintf(stderr, "Usage: %s <num>\en", argv[0]);
75 x = strtoull(argv[1], NULL, 0);
76 printf("%#" PRIx64 " ==> %#" PRIx64 "\en", x, bswap_64(x));