3 ms·
There's a really neat way to express asymmetric numbers that generalizes from both unsigned numbers and standard 2's complement signed numbers. It's easiest to
by im3w1l 4y ago
There's a really neat way to express asymmetric numbers that generalizes from both unsigned numbers and standard 2's complement signed numbers.
It's easiest to explain in terms of how to interpret a particular bitpattern. As the first step, interpret the bitpattern as an unsigned int, u.
If u <= T, for some threshold T, then we are done, the final value is u. If u > T, then we interpret it as the negative number u - UINT_MAX.
T = UINT_MAX gives you the unsigned numbers, and T = INT_MAX gives you the two's complement.
Because of modulus intense handwaving it's also easy to do addition, subtraction and multiplication using this representation.