frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

How to pack ternary numbers in 8-bit bytes

https://compilade.net/blog/ternary-packing
1•JoshTriplett•1h ago

Comments

JoshTriplett•1h ago
It's impressive how close to optimal this is.

You can beat the efficiency of 5 trits in 8 bits (1.6) with as few as 17 trits in 27 bits (~1.588), but once you account for rounding up to a whole number of bytes for practical reasons, then beating the efficiency requires going to at least 111 trits in 176 bits (~1.586), or perhaps more practically for fast unpacking, 161 trits in 256 bits (~1.59).

At that level, even if you have, say, 27B trits, the more efficient encodings would save something like 38-45MB (theoretical limit ~48MB), likely at the cost of some slowdown.