Four representation types are illustrated here: uint, two's complement, one's complement and biased representation.
| Shorthand | Meaning |
|---|---|
| uint | Unsigned integer |
| 2C | Two's complement |
| 1C | One's complement |
| bias | Biased binary representation |
A binary representation can be seen as a mapping from n bits to a decimal number:
| Encoding | Weights | Bias |
|---|---|---|
uint |
||
2C |
||
1C |
||
biased |
Change the bit values and bias in the widget below to see how it changes the representation of numbers:
+ + - =
Note: bias is 0 for representation
This is the simplest representation.
Sign of the top weight is flipped to . Other weights stay the same.
This is the same ring as uint. This is because it changes half of the numbers by . And in the ring .
Read the bits as a plain uint, then subtract a fixed constant . Here .
Subtracting a constant does not reorder anything, so bigger bit pattern means bigger number. You can compare two biased numbers, signs and all, with an unsigned comparison of their bits. That is why float exponents are stored this way.
The top weight is . Negating a number is just flipping every bit.
Range: , so for
The mapping is not injective: 000 and 111 both map to .
Since in the ring, we have:
This equation explains the well known relationship: to get the two's complement representation of a number, you can take the one's complement and add 1.
| bits | uint |
2C |
1C |
bias () |
|---|---|---|---|---|