Beginner Topic 3 of 51 Computer Architecture & Logic
Two's Complement
Standard encoding of signed integers in binary.
How it works
Two's complement represents signed integers by letting the most significant bit carry a negative weight. To negate a number, invert all bits and add one. With n bits the range is minus 2 to the power n minus 1 up to 2 to the power n minus 1 minus 1. Addition and subtraction use the same hardware for signed and unsigned values, and there is only one zero.
Where it is used
Nearly every modern CPU and programming language stores signed integers this way. It explains overflow wraparound, sign extension when widening values and why bitwise negation works as it does.
Common pitfall
The range is asymmetric, so negating the most negative value overflows to itself. Signed overflow is undefined behavior in C. Comparing signed and unsigned values gives surprising results, and right shifts of negative numbers may be arithmetic or logical depending on the language. Always sign-extend, not zero-extend, when widening signed data.
Where it fits in the course
Two's Complement is topic 3 of 51 in Computer Architecture & Logic, rated Beginner. It follows Hexadecimal and Octal. The next topic is Floating Point Representation.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Computer Architecture & Logic quiz.
- Explore the Binary & Two's Complement visualizer: Flip bits and watch the number change.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Computer Architecture & Logic quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Two's Complement?
Where do people use Two's Complement?
What is the most common mistake with Two's Complement?
What should I learn before this topic?
How can I practice it?
Is Two's Complement hard to learn?
How long does it take to learn Two's Complement?
Which topics are related to Two's Complement?
What should I study after Two's Complement?
Related topics
- Hexadecimal and Octal (Computer Architecture & Logic)
- Floating Point Representation (Computer Architecture & Logic)
- Binary Number System (Computer Architecture & Logic)
- Character Encoding (Computer Architecture & Logic)