MACH-SWAP(3)
β¨ NAME β¨
okay so bestie, this is MACH-SWAP(3) from the Library Functions Manual, and it's giving machine-independent access to byte-ordered data π
β¨ The whole squad is: beswap2, beswap4, beswap8, beieeeftoa32, beieeeftoa64, beieeeftoa80, beload2, beload4, beload8, leswap2, leswap4, leswap8, leieeeftoa32, leieeeftoa64, leieeeftoa80, leload2, leload4, leload8, ieeeftoa32, and ieeeftoa64. No cap, that's the roster π«Ά
πΈ SYNOPSIS πΈ
#include <u.h>
#include <libc.h>
#include <mach.h>
u16int beswap2(u16int u)
u32int beswap4(u32int u)
u64int beswap8(u64int u)
int beieeeftoa32(char *a, uint n, void *f)
int beieeeftoa64(char *a, uint n, void *f)
int beieeeftoa80(char *a, uint n, void *f)
u16int beload2(uchar *p)
u32int beload4(uchar *p)
u64int beload8(uchar *p)
u16int leswap2(u16int u)
u32int leswap4(u32int u)
u64int leswap8(u64int u)
int leieeeftoa32(char *a, uint n, void *f)
int leieeeftoa64(char *a, uint n, void *f)
int leieeeftoa80(char *a, uint n, void *f)
u16int leload2(uchar *p)
u32int leload4(uchar *p)
u64int leload8(uchar *p)
int ieeeftoa32(char *a, uint n, u32int u)
int ieeeftoa64(char *a, uint n, u32int hi, u32int lo)
π¦ DESCRIPTION π¦
These functions are your besties for machine-independent access to data in a particular byte order β literally the vibe is "bytes, but make it portable" π
beswap2,beswap4,beswap8β return the 2-byte, 4-byte, and 8-byte big-endian representation of the bytes inval, respectively. (Yes, the original saysvalβ we are keeping that word exactly, bestie π«Ά)beload2,beload4,beload8β return the 2-byte, 4-byte, and 8-byte big-endian interpretation of the bytes atp, respectively. Iconic little loaders β¨beieeeftoa32,beieeeftoa64,beieeeftoa80β format the big-endian 4-byte, 8-byte, or 10-byte IEEE floating-point value atfinto then-byte string buffera. Floating-point to string, but make it big-endian πleswap2,leswap4, etc. β the little-endian equivalents of the routines just described. Little-endian girlies, this one's for you πieeeftoa32,ieeeftoa64β format a local machine byte-order floating-point value into then-byte string buffera.ieeeftoa32expects a 32-bit floating-point value stored in the bits ofu.ieeeftoa64expects a 64-bit floating-point value whose high 32-bits are inhiand low 32-bits are inlo. absolutely ate that π
π SOURCE π
/src/libmach
π SEE ALSO π
mach(3) β go say hi, iykyk π
okay bestie, that's the page β the footer is just the manual name again, no date or version line to report, and the source lives at /src/libmach. mwah π
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms