convertimate Two’s complement

Two’s complement converter

In 8 bits, −5 is 11111011: invert the bits of 5 and add one. Convert a signed integer to its 8, 16 or 32-bit two’s complement pattern, or read a hex or binary pattern as a signed value.

1101 0110bin (8-bit)

The smallest signed register that holds -42 is 7-bit.

What it means

Where does it sit?

A dash means the value does not fit that width: an 8-bit register holds −128 to 127.

Every unit

That integer in every register

Learn

Three things worth knowing

Keep going

What people use next

Shortcuts

Popular integer conversions

Background

About two’s complement

Almost every processor stores signed integers in two’s complement. A negative number −n is stored as 2bits − n, so in a byte −1 is 255 (1111 1111) and −128 is 128 (1000 0000). The top bit tells the sign.

The trick makes addition work without special cases: adding 1 to 1111 1111 overflows to 0000 0000, which is exactly −1 + 1.

Embed this converter