Home

be32toh

be32toh is a macro or inline function used in C and C++ to convert a 32-bit unsigned integer from big-endian byte order to the host's native byte order. The name conveys its purpose: be32toh means “big-endian 32 to host.” It is commonly used when reading binary data formats or network protocols that specify 32-bit fields in big-endian representation.

The behavior of be32toh depends on the host's endianness. On a big-endian system, be32toh(x) typically returns

Be32toh is typically defined in system headers such as endian.h or sys/endian.h, with variations across Unix-like

The macro is closely related to htobe32, which performs the inverse operation (host to big-endian). In network

Usage is common when parsing binary formats or files that specify big-endian 32-bit fields, ensuring that subsequent

x
unchanged.
On
a
little-endian
system,
it
swaps
the
byte
order
of
the
32-bit
value
so
that
the
value
is
interpreted
correctly
in
the
host’s
native
representation.
For
example,
be32toh(0x01020304)
would
yield
0x04030201
on
a
little-endian
host.
platforms.
Its
availability
and
exact
naming
can
differ;
some
systems
may
provide
be32toh
alongside
be16toh
and
be64toh,
while
others
expose
similar
facilities
under
different
headers
or
via
alternative
functions.
programming,
be32toh
is
conceptually
similar
to
ntohl,
but
be32toh
emphasizes
conversion
from
a
big-endian
representation
regardless
of
whether
the
data
originated
from
a
network
source.
arithmetic
and
comparisons
use
the
host’s
native
byte
order.
If
platform
support
is
absent,
developers
may
fall
back
to
explicit
byte-swapping
routines
or
portable
alternatives.
See
also
be16toh,
be64toh,
htobe32,
and
ntohl.