Use the two’s complement number system to represent positive and negative 8-bit binary integers

Resources | Subject Notes | Computer Science

Data Representation - Two's Complement

Data Representation: Two's Complement for 8-bit Integers

This section explains how to represent both positive and negative integers using the two's complement number system with 8 bits. This is a common method used in computers to represent signed integers.

Understanding Binary Representation

Recall that binary is a base-2 number system using only 0 and 1. Each bit represents a power of 2, from right to left: $2^0$, $2^1$, $2^2$, ..., $2^7$ (for 8 bits).

Positive Integers in 8-bit Two's Complement

For positive integers, the two's complement representation is the same as the standard binary representation.

For example:

  • Decimal 0: Binary 00000000
  • Decimal 1: Binary 00000001
  • Decimal 2: Binary 00000010
  • Decimal 127: Binary 01111111

Negative Integers in 8-bit Two's Complement

To represent negative integers, we use the two's complement method. This involves the following steps:

  1. Find the binary representation of the absolute value of the number.
  2. Invert all the bits (change 0s to 1s and 1s to 0s). This is called the one's complement.
  3. Add 1 to the one's complement. This gives the two's complement representation.

Example: Representing -5 in 8-bit two's complement

  1. Absolute value of -5 is 5. Binary representation of 5 is 00000101.
  2. One's complement of 00000101 is 11111010 (invert the bits).
  3. Add 1 to the one's complement: 11111010 + 1 = 11111011.

Therefore, the 8-bit two's complement representation of -5 is 11111011.

Table of Positive and Negative Integers in 8-bit Two's Complement

The following table shows the two's complement representation of integers from -128 to +127.

Decimal Binary
0 00000000
1 00000001
2 00000010
3 00000011
4 00000100
5 00000101
127 01111111
128 10000000
129 10000001
-1 11111111
-2 11111110
-127 10000000

Advantages of Two's Complement

Two's complement simplifies arithmetic operations in computers because addition and subtraction can be performed using the same circuitry, regardless of the sign of the numbers.