You are on page 1of 2

Two’s Complement

Two's complement is a binary representation used to represent both positive


and negative numbers in a way that simplifies arithmetic operations like addition
and subtraction. In two's complement, the most significant bit (leftmost bit) is
used as the sign bit, where 0 represents a positive number and 1 represents a
negative number. Here's how it works:
1. Positive Numbers: To represent a positive number in two's complement,
simply convert it to its binary representation as you normally would.
2. Negative Numbers: To represent a negative number in two's complement,
follow these steps:
3. a. Start with the binary representation of the absolute value of the
number.
4. b. Invert (flip) all the bits (change 0s to 1s and 1s to 0s) in that binary
representation.
5. c. Add 1 to the inverted binary representation.
Here's an example to illustrate two's complement for both positive and negative
numbers:
Positive Number: 12
• The binary representation of 12 is 1100.
Negative Number: -12
• Absolute value of -12 is 12, which is 1100 in binary.
• Invert all the bits: 0011.
• Add 1 to the inverted binary: 0011 + 1 = 0100.
So, -12 is represented as 0100 in two's complement.
Here's another example:
Positive Number: 7
• The binary representation of 7 is 0111.
Negative Number: -7
• Absolute value of -7 is 7, which is 0111 in binary.
• Invert all the bits: 1000.
• Add 1 to the inverted binary: 1000 + 1 = 1001.
So, -7 is represented as 1001 in two's complement.
Two's complement is advantageous because it simplifies the hardware required
for arithmetic operations and ensures that the range of representable numbers
is symmetric around zero. When performing addition and subtraction using
two's complement numbers, the rules are the same as for regular binary
numbers, but with the overflow and carry bits taken into account to handle
overflow and underflow situations.

You might also like