]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/bswap.3
All pages: Remove the 5th argument to .TH
[thirdparty/man-pages.git] / man3 / bswap.3
1 .\" Copyright (C) 2016 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .TH BSWAP 3 2021-06-20 "Linux man-pages (unreleased)"
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 .PP
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 These functions are GNU extensions.
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 .PP
33 .in +4n
34 .EX
35 $ \fB./a.out 0x0123456789abcdef\fP
36 0x123456789abcdef ==> 0xefcdab8967452301
37 .EE
38 .in
39 .SS Program source
40 \&
41 .EX
42 #include <stdio.h>
43 #include <stdint.h>
44 #include <stdlib.h>
45 #include <inttypes.h>
46 #include <byteswap.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>\en", argv[0]);
55 exit(EXIT_FAILURE);
56 }
57
58 x = strtoull(argv[1], NULL, 0);
59 printf("%#" PRIx64 " ==> %#" PRIx64 "\en", x, bswap_64(x));
60
61 exit(EXIT_SUCCESS);
62 }
63 .EE
64 .SH SEE ALSO
65 .BR byteorder (3),
66 .BR endian (3)