Debian Codegraph @

upstream/debian-trixie/man3/bswap.3

raw
1 .\" Copyright (C) 2016 Michael Kerrisk <[email protected]>
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .TH bswap 3 2024-06-15 "Linux man-pages 6.9.1"
6 .SH NAME
7 bswap_16, bswap_32, bswap_64 \- reverse order of bytes
8 .SH LIBRARY
9 Standard C library
10 .RI ( libc ", " \-lc )
11 .SH SYNOPSIS
12 .nf
13 .B #include <byteswap.h>
14 .P
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 );
18 .fi
19 .SH DESCRIPTION
20 These functions return a value in which the order of the bytes
21 in their 2-, 4-, or 8-byte arguments is reversed.
22 .SH RETURN VALUE
23 These functions return the value of their argument with the bytes reversed.
24 .SH ERRORS
25 These functions always succeed.
26 .SH STANDARDS
27 GNU.
28 .SH EXAMPLES
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:
32 .P
33 .in +4n
34 .EX
35 $ \fB./a.out 0x0123456789abcdef\fP
36 0x123456789abcdef ==> 0xefcdab8967452301
37 .EE
38 .in
39 .SS Program source
40 \&
41 .\" SRC BEGIN (bswap.c)
42 .EX
43 #include <byteswap.h>
44 #include <inttypes.h>
45 #include <stdint.h>
46 #include <stdio.h>
47 #include <stdlib.h>
48 \&
49 int
50 main(int argc, char *argv[])
51 {
52 uint64_t x;
53 \&
54 if (argc != 2) {
55 fprintf(stderr, "Usage: %s <num>\[rs]n", argv[0]);
56 exit(EXIT_FAILURE);
57 }
58 \&
59 x = strtoull(argv[1], NULL, 0);
60 printf("%#" PRIx64 " ==> %#" PRIx64 "\[rs]n", x, bswap_64(x));
61 \&
62 exit(EXIT_SUCCESS);
63 }
64 .EE
65 .\" SRC END
66 .SH SEE ALSO
67 .BR byteorder (3),
68 .BR endian (3)