byteorder(3bsd)
β¨ byteorder β the manual page bestie π
okay so this is byteorder(3bsd), from the LOCAL section, and it's literally the whole "move numbers in and out of bytes without caring where they sit in memory" situation. no cap, it's short, it's iconic, let's go π
π NAME π
be16enc, be16dec, be32enc, be32dec, be64enc, be64dec, le16enc, le16dec, le32enc, le32dec, le64enc, le64dec β byte order operations π¦
π LIBRARY π
Utility functions from BSD systems β that's libbsd, and you link it with -lbsd. yes, the whole point is you get the BSD goodies. periodt π
πΈ SYNOPSIS πΈ
#include <sys/endian.h>
(btw, peep libbsd(7) for how the include situation actually works β it's giving "read the fine print" energy π)
okay here are the decoders, they hand you a number back:
uint16_t
be16dec(const void *);
uint32_t
be32dec(const void *);
uint64_t
be64dec(const void *);
uint16_t
le16dec(const void *);
uint32_t
le32dec(const void *);
uint64_t
le64dec(const void *);
and here are the encoders, they return void because they're busy writing into your buffer, no time to chat:
void
be16enc(void *, uint16_t);
void
be32enc(void *, uint32_t);
void
be64enc(void *, uint64_t);
void
le16enc(void *, uint16_t);
void
le32enc(void *, uint32_t);
void
le64enc(void *, uint64_t);
π§ DESCRIPTION π§
so listen. be16enc(), be16dec(), be32enc(), be32dec(), be64enc(), be64dec(), le16enc(), le16dec(), le32enc(), le32dec(), le64enc(), and le64dec() encode and decode integers to/from byte strings on any alignment in big/little endian format.
that's the whole vibe, bestie. you got your be squad (big endian) and your le squad (little endian), 16/32/64 flavors each, and the any alignment part means you do NOT have to sit there stressing about whether your pointer is aligned. it just works. main character energy fr fr π
π«Ά reminder: if you're reaching for these, double-check which endianness the thing you're talking to actually wants. big vs little is not a vibe, it's a fact. π
π SEE ALSO π
byteorder(3)β yeah it points at its own sibling, that's just how the family is π
π°οΈ HISTORY π°οΈ
The encode/decode functions first appeared in FreeBSD 5.1. so they've been eating since way back, we love a legacy icon π
and that's a wrap, gorgeous π this page is Debian's, dated April 29, 2002 β go forth and byte-swap responsibly, mwah πβ
π¦ where this page comes from
- alpine 3.22: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.23: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.24: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- arch rolling: libbsd 0.12.2-2 Β· custom
- debian bookworm: libbsd-dev 0.11.7-2
- debian trixie: libbsd-dev 0.12.2-2
- epel 10: libbsd-devel 0.12.2-4.el10_0 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- epel 9: libbsd-devel 0.12.2-1.el9 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- nixos 26.05: libbsd 0.12.2
- nixpkgs unstable: libbsd 0.12.2
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- ubuntu noble: libbsd-dev 0.12.1-1build1
- ubuntu noble: libbsd-dev 0.12.1-1build1.1
- ubuntu questing: libbsd-dev 0.12.2-2build1
- ubuntu resolute: libbsd-dev 0.12.2-2build2
- ubuntu stonking: libbsd-dev 0.12.2-3
- Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms