Algorithms

Two's complement

The way computers store negative integers: flip the value's bits and add 1. It has a single zero and lets you subtract by adding.

Example

−5 in 8 bits: 5 is 0000 0101, flipped 1111 1010, plus 1: 1111 1011. And 5 + (−5) gives 0.

Test yourself: Two's complement

How numbers are stored

A two's complement byte goes from −128 to ___.

Lessons that use it

More algorithms terms

All terms →

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.