xref: /freebsd/share/man/man9/byteorder.9 (revision c17d43407fe04133a94055b0dbc7ea8965654a9f)
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 March 5, 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/param.h
46.Ft uint16_t
47.Fn be16toh "uint16_t big16"
48.Ft uint32_t
49.Fn be32toh "uint32_t big32"
50.Ft uint64_t
51.Fn be64toh "uint64_t big64"
52.Ft uint16_t
53.Fn htobe16 "uint16_t host16"
54.Ft uint32_t
55.Fn htobe32 "uint32_t host32"
56.Ft uint64_t
57.Fn htobe64 "uint64_t host64"
58.Ft uint16_t
59.Fn htole16 "uint16_t host16"
60.Ft uint32_t
61.Fn htole32 "uint32_t host32"
62.Ft uint64_t
63.Fn htole64 "uint64_t host64"
64.Ft uint16_t
65.Fn le16toh "uint16_t little16"
66.Ft uint32_t
67.Fn le32toh "uint32_t little32"
68.Ft uint64_t
69.Fn le64toh "uint64_t little64"
70.Sh DESCRIPTION
71The
72.Fn be16toh ,
73.Fn be32toh ,
74and
75.Fn be64toh
76functions return a big endian byte ordered integer
77converted to the system's native byte order.
78The return value will be the same as the argument on big endian systems.
79.Pp
80The
81.Fn le16toh ,
82.Fn le32toh ,
83and
84.Fn le64toh
85functions return a little endian byte ordered integer
86converted to the system's native byte order.
87The return value will be the same as the argument on little endian systems.
88.Pp
89The
90.Fn htobe16 ,
91.Fn htobe32 ,
92and
93.Fn htobe64
94functions return a integer in the system's native
95byte order converted to big endian byte order.
96The return value will be the same as the argument on big endian systems.
97.Pp
98The
99.Fn htole16 ,
100.Fn htole32 ,
101and
102.Fn htole64
103functions return a integer in the system's native
104byte order converted to little endian byte order.
105The return value will be the same as the argument on little endian systems.
106.Sh SEE ALSO
107.Xr byteorder 3
108.Sh HISTORY
109These functions first appeared in
110.Fx 5.0 ,
111and were originally developed by the
112.Nx
113project.
114