|
FZGPUModules 2.0
GPU-accelerated modular compression pipelines
|
Negabinary (base -2) integer encoding helpers. More...
#include <cstdint>#include <type_traits>Go to the source code of this file.
Classes | |
| struct | fz::Negabinary< T > |
Negabinary (base -2) integer encoding helpers.
Negabinary (base -2) encoding.
Maps a signed two's-complement integer to an unsigned negabinary representation using the compact XOR-mask formula:
encode: u = (n + MASK) ^ MASK // signed → unsigned decode: n = (SInt)((u ^ MASK) - MASK) // unsigned → signed (NOT self-inverse)
where MASK = 0xAA…A (alternating bits: 1010…1010) for the given width.
Properties:
Design constraints (mirrors zigzag.h):
Usage: using NB = fz::Negabinary<int32_t>; uint32_t u = NB::encode(-3); // → negabinary representation int32_t n = NB::decode(u); // → -3