xref: /freebsd/share/man/man9/byteorder.9 (revision 3ff369fed2a08f32dda232c10470b949bef9489f)
1.\" Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd April 29, 2002
28.Dt BYTEORDER 9
29.Os
30.Sh NAME
31.Nm be16toh ,
32.Nm be32toh ,
33.Nm be64toh ,
34.Nm htobe16 ,
35.Nm htobe32 ,
36.Nm htobe64 ,
37.Nm htole16 ,
38.Nm htole32 ,
39.Nm htole64 ,
40.Nm le16toh ,
41.Nm le32toh ,
42.Nm le64toh
43.Nd convert values between big endian, little endian, and host byte order
44.Sh SYNOPSIS
45.In sys/endian.h
46.Ft uint16_t
47.Fn bswap16 "uint16_t int16"
48.Ft uint32_t
49.Fn bswap32 "uint32_t int32"
50.Ft uint64_t
51.Fn bswap64 "uint64_t int64"
52.Ft uint16_t
53.Fn be16toh "uint16_t big16"
54.Ft uint32_t
55.Fn be32toh "uint32_t big32"
56.Ft uint64_t
57.Fn be64toh "uint64_t big64"
58.Ft uint16_t
59.Fn htobe16 "uint16_t host16"
60.Ft uint32_t
61.Fn htobe32 "uint32_t host32"
62.Ft uint64_t
63.Fn htobe64 "uint64_t host64"
64.Ft uint16_t
65.Fn htole16 "uint16_t host16"
66.Ft uint32_t
67.Fn htole32 "uint32_t host32"
68.Ft uint64_t
69.Fn htole64 "uint64_t host64"
70.Ft uint16_t
71.Fn le16toh "uint16_t little16"
72.Ft uint32_t
73.Fn le32toh "uint32_t little32"
74.Ft uint64_t
75.Fn le64toh "uint64_t little64"
76.Sh DESCRIPTION
77The
78.Fn bswap16 ,
79.Fn bswap32 ,
80and
81.Fn bswap64
82functions return a byte order swapped integer.
83On big endian systems, the number is converted to little endian byte order.
84On little endian systems, the number is converted to big endian byte order.
85.Pp
86The
87.Fn be16toh ,
88.Fn be32toh ,
89and
90.Fn be64toh
91functions return a big endian byte ordered integer
92converted to the system's native byte order.
93The return value will be the same as the argument on big endian systems.
94.Pp
95The
96.Fn le16toh ,
97.Fn le32toh ,
98and
99.Fn le64toh
100functions return a little endian byte ordered integer
101converted to the system's native byte order.
102The return value will be the same as the argument on little endian systems.
103.Pp
104The
105.Fn htobe16 ,
106.Fn htobe32 ,
107and
108.Fn htobe64
109functions return a integer in the system's native
110byte order converted to big endian byte order.
111The return value will be the same as the argument on big endian systems.
112.Pp
113The
114.Fn htole16 ,
115.Fn htole32 ,
116and
117.Fn htole64
118functions return a integer in the system's native
119byte order converted to little endian byte order.
120The return value will be the same as the argument on little endian systems.
121.Sh SEE ALSO
122.Xr byteorder 3
123.Sh HISTORY
124These functions first appeared in
125.Fx 5.0 ,
126and were originally developed by the
127.Nx
128project.
129