1BSWAP(3)                   Linux Programmer's Manual                  BSWAP(3)
2
3
4

NAME

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

SYNOPSIS

9       #include <byteswap.h>
10
11       bswap_16(x);
12       bswap_32(x);
13       bswap_64(x);
14

DESCRIPTION

16       These  macros  return  a value in which the order of the bytes in their
17       2-, 4-, or 8-byte arguments is reversed.
18

RETURN VALUE

20       These macros  return  the  value  of  their  argument  with  the  bytes
21       reversed.
22

ERRORS

24       These macros always succeed.
25

CONFORMING TO

27       These macros are GNU extensions.
28

EXAMPLE

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 = strtoul(argv[1], NULL, 0);
56           printf("0x%" PRIx64 " ==> 0x%" PRIx64 "\n", x, bswap_64(x));
57
58           exit(EXIT_SUCCESS);
59       }
60

SEE ALSO

62       byteorder(3), endian(3)
63

COLOPHON

65       This  page  is  part of release 4.16 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                             2017-09-15                          BSWAP(3)
Impressum