Maths & numbers

Two’s complement bit representation calculator

Represent a signed integer in a chosen two’s complement width.

Your numbers

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

The leading bit has negative weight. For an eight-bit value, its weight is −128.

THE FORMULAEncode n mod 2ʷ in w bits

A worked example

At eight bits, −18 is represented as 238, or 11101110.

Good to know

The signed input must fit the selected width.

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.

Eight bits one one one zero one one one zero represent negative eighteen in signed two’s complement1-12816413201618141201Signed value = −18
The active weights sum to −128 + 64 + 32 + 8 + 4 + 2 = −18. An unsigned interpretation of the same bits gives 238.

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.

Find your calculator

Start typing to explore the library.