]>
Commit | Line | Data |
---|---|---|
9f0b7bd6 MK |
1 | .\" Copyright (C) 2016 Michael Kerrisk <mtk.manpages@gmail.com> |
2 | .\" | |
3 | .\" %%%LICENSE_START(VERBATIM) | |
4 | .\" Permission is granted to make and distribute verbatim copies of this | |
5 | .\" manual provided the copyright notice and this permission notice are | |
6 | .\" preserved on all copies. | |
7 | .\" | |
8 | .\" Permission is granted to copy and distribute modified versions of this | |
9 | .\" manual under the conditions for verbatim copying, provided that the | |
10 | .\" entire resulting derived work is distributed under the terms of a | |
11 | .\" permission notice identical to this one. | |
12 | .\" | |
13 | .\" Since the Linux kernel and libraries are constantly changing, this | |
14 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
15 | .\" responsibility for errors or omissions, or for damages resulting from | |
16 | .\" the use of the information contained herein. The author(s) may not | |
17 | .\" have taken the same level of care in the production of this manual, | |
18 | .\" which is licensed free of charge, as they might when working | |
19 | .\" professionally. | |
20 | .\" | |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by | |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
23 | .\" %%%LICENSE_END | |
24 | .\" | |
4b8c67d9 | 25 | .TH BSWAP 3 2017-09-15 "Linux" "Linux Programmer's Manual" |
9f0b7bd6 MK |
26 | .SH NAME |
27 | bswap_16, bswap_32, bswap_64 \- reverse order of bytes | |
28 | .SH SYNOPSIS | |
29 | .nf | |
30 | .B #include <byteswap.h> | |
dbfe9c70 | 31 | .PP |
9f0b7bd6 MK |
32 | .BI bswap_16( x ); |
33 | .BI bswap_32( x ); | |
34 | .BI bswap_64( x ); | |
35 | .fi | |
36 | .SH DESCRIPTION | |
37 | These macros return a value in which the order of the bytes | |
38 | in their 2-, 4-, or 8-byte arguments is reversed. | |
39 | .SH RETURN VALUE | |
40 | These macros return the value of their argument with the bytes reversed. | |
41 | .SH ERRORS | |
42 | These macros always succeed. | |
43 | .SH CONFORMING TO | |
44 | These macros are GNU extensions. | |
45 | .SH EXAMPLE | |
46 | The program below swaps the bytes of the 8-byte integer supplied as | |
47 | its command-line argument. | |
48 | The following shell session demonstrates the use of the program: | |
847e0d88 | 49 | .PP |
9f0b7bd6 | 50 | .in +4n |
b8302363 | 51 | .EX |
9f0b7bd6 MK |
52 | $ \fB./a.out 0x0123456789abcdef\fP |
53 | 0x123456789abcdef ==> 0xefcdab8967452301 | |
b8302363 | 54 | .EE |
e646a1ba | 55 | .in |
9f0b7bd6 MK |
56 | .SS Program source |
57 | \& | |
e7d0bb47 | 58 | .EX |
9f0b7bd6 MK |
59 | #include <stdio.h> |
60 | #include <stdint.h> | |
61 | #include <stdlib.h> | |
62 | #include <inttypes.h> | |
63 | #include <byteswap.h> | |
64 | ||
65 | int | |
66 | main(int argc, char *argv[]) | |
67 | { | |
68 | uint64_t x; | |
69 | ||
70 | if (argc != 2) { | |
71 | fprintf(stderr, "Usage: %s <num>\\n", argv[0]); | |
72 | exit(EXIT_FAILURE); | |
73 | } | |
74 | ||
75 | x = strtoul(argv[1], NULL, 0); | |
76 | printf("0x%" PRIx64 " ==> 0x%" PRIx64 "\\n", x, bswap_64(x)); | |
77 | ||
78 | exit(EXIT_SUCCESS); | |
79 | } | |
e7d0bb47 | 80 | .EE |
9f0b7bd6 MK |
81 | .SH SEE ALSO |
82 | .BR byteorder (3), | |
83 | .BR endian (3) |