1BSWAP(3) Linux Programmer's Manual BSWAP(3)
2
3
4
6 bswap_16, bswap_32, bswap_64 - reverse order of bytes
7
9 #include <byteswap.h>
10
11 uint16_t bswap_16(uint16_t x);
12 uint32_t bswap_32(uint32_t x);
13 uint64_t bswap_64(uint64_t x);
14
16 These functions return a value in which the order of the bytes in their
17 2-, 4-, or 8-byte arguments is reversed.
18
20 These functions return the value of their argument with the bytes re‐
21 versed.
22
24 These functions always succeed.
25
27 These functions are GNU extensions.
28
30 The program below swaps the bytes of the 8-byte integer supplied as its
31 command-line argument. The following shell session demonstrates the
32 use of the program:
33
34 $ ./a.out 0x0123456789abcdef
35 0x123456789abcdef ==> 0xefcdab8967452301
36
37 Program source
38
39 #include <stdio.h>
40 #include <stdint.h>
41 #include <stdlib.h>
42 #include <inttypes.h>
43 #include <byteswap.h>
44
45 int
46 main(int argc, char *argv[])
47 {
48 uint64_t x;
49
50 if (argc != 2) {
51 fprintf(stderr, "Usage: %s <num>\n", argv[0]);
52 exit(EXIT_FAILURE);
53 }
54
55 x = strtoull(argv[1], NULL, 0);
56 printf("%#" PRIx64 " ==> %#" PRIx64 "\n", x, bswap_64(x));
57
58 exit(EXIT_SUCCESS);
59 }
60
62 byteorder(3), endian(3)
63
65 This page is part of release 5.12 of the Linux man-pages project. A
66 description of the project, information about reporting bugs, and the
67 latest version of this page, can be found at
68 https://www.kernel.org/doc/man-pages/.
69
70
71
72Linux 2021-06-20 BSWAP(3)