All courses › Embedded Systems and Instrumentation › Two's Complement
Two's Complement
Two's complement is the standard way computers represent negative integers in a fixed number of bits. The top bit signals the sign, and a negative number is represented as the unsigned bit pattern of . This makes addition work the same way for positive and negative numbers, with no special cases.
bit pattern for a negative number in n-bit two's complement
range of an n-bit signed integer
Symbols
| number of bits | ||
| the number's absolute value |
Example
as 8-bit two's complement:
.
Remember to subtract from , not just flip the sign bit – that gives the wrong answer.
Practise number systems and digital logic for free →
← Number Systems · Logic Gates →
Part of Embedded Systems and Instrumentation: Number systems and digital logic.