How this calculation works
The leading bit has negative weight. For an eight-bit value, its weight is −128.
Encode n mod 2ʷ in w bitsA worked example
At eight bits, −18 is represented as 238, or 11101110.
Good to know
The signed input must fit the selected width.
Reference: NIST DLMF, Functions of Number Theory (opens in a new tab) ↗
Encode the signed value at a stated width
For −18 at width eight, reduce the value modulo 2⁸ = 256. The least nonnegative residue is 256 − 18 = 238, whose eight-bit binary representation is 11101110. Leading zeros would be retained when needed to preserve the selected width.
Decode the result using signed bit weights. The leading bit contributes −128, and the remaining active positions contribute 64 + 32 + 8 + 4 + 2 = 110. Their sum is −18. The sign interpretation belongs to the width and encoding convention, not to the string of digits by itself.
Check the signed range before interpreting the bits
An eight-bit signed value ranges from −128 through 127. The input −129 cannot fit and is rejected. At width sixteen, the same integer −18 has a different representation, 1111111111101110, because the higher bits extend the sign. Always retain width information alongside a stored or displayed bit pattern.
The One’s complement within a fixed width calculator flips bits, which is one step in constructing a negative two’s complement representation. Starting from +18, flip the eight bits and add one to obtain −18. The Integer quotient and remainder calculator can also check the modular residue. Positive values use ordinary binary notation padded with zeros, provided they remain inside the signed range.
A few questions, answered
Can the same bits represent an unsigned number?
Yes. Interpreted as unsigned, 11101110 is 238. At signed eight-bit two’s complement it represents −18.
Why does the most negative value lack a positive counterpart?
At width w, the signed range is −2^(w−1) through 2^(w−1) − 1. There is one additional representable negative value.