1bswap(3)                   Library Functions Manual                   bswap(3)
2
3
4

NAME

6       bswap_16, bswap_32, bswap_64 - reverse order of bytes
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <byteswap.h>
13
14       uint16_t bswap_16(uint16_t x);
15       uint32_t bswap_32(uint32_t x);
16       uint64_t bswap_64(uint64_t x);
17

DESCRIPTION

19       These functions return a value in which the order of the bytes in their
20       2-, 4-, or 8-byte arguments is reversed.
21

RETURN VALUE

23       These functions return the value of their argument with the  bytes  re‐
24       versed.
25

ERRORS

27       These functions always succeed.
28

STANDARDS

30       GNU.
31

EXAMPLES

33       The program below swaps the bytes of the 8-byte integer supplied as its
34       command-line argument.  The following shell  session  demonstrates  the
35       use of the program:
36
37           $ ./a.out 0x0123456789abcdef
38           0x123456789abcdef ==> 0xefcdab8967452301
39
40   Program source
41
42       #include <byteswap.h>
43       #include <inttypes.h>
44       #include <stdint.h>
45       #include <stdio.h>
46       #include <stdlib.h>
47
48       int
49       main(int argc, char *argv[])
50       {
51           uint64_t x;
52
53           if (argc != 2) {
54               fprintf(stderr, "Usage: %s <num>\n", argv[0]);
55               exit(EXIT_FAILURE);
56           }
57
58           x = strtoull(argv[1], NULL, 0);
59           printf("%#" PRIx64 " ==> %#" PRIx64 "\n", x, bswap_64(x));
60
61           exit(EXIT_SUCCESS);
62       }
63

SEE ALSO

65       byteorder(3), endian(3)
66
67
68
69Linux man-pages 6.04              2023-03-30                          bswap(3)
Impressum