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.

Read the result

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

The primary result is labeled “Bit representation”. Keep the input definitions in view when comparing this result with another method.

Try a related calculation

The signed input must fit the selected width.

For a related exercise, try the greatest common divisor.

A few questions, answered

How can I check the default inputs by hand?

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

Which rule does this calculator apply?

Encode n mod 2ʷ in w bits

Find your calculator

Start typing to explore the library.