Negative binary numbers are often represented using two’s complement notation. This system allows for the representation of both positive and negative integers using binary numbers. Here’s a breakdown of how it works:
1. Two’s Complement Representation:
- Positive numbers are represented as usual in binary.
- Negative numbers are represented by first finding the binary representation of the positive number, then inverting all the bits (changing 0s to 1s and 1s to 0s), and finally adding 1 to the result.
Example: Representing -5 in an 8-bit system
Step 1: Convert the positive number to binary
- The binary representation of 5 is: 5=000001015 = 00000101
Step 2: Invert the bits
- Inverting each bit of 5: 00000101→1111101000000101 \rightarrow 11111010
Step 3: Add 1
- Adding 1 to the result: 11111010+1=1111101
Thus, -5 in two’s complement representation in an 8-bit system is 11111011.
General Process for Two’s Complement
- Write the binary representation of the positive value.
- Invert all the bits.
- Add 1 to the result.
Properties of Two’s Complement:
- Range: For an n-bit system, two’s complement can represent integers in the range from −2(n−1)-2
- Example for 8-bit: Range is from -128 to 127.
- Arithmetic: Addition, subtraction, and other operations are straightforward in two’s complement, as the hardware can handle negative numbers directly without needing to distinguish between signed and unsigned values.
This system allows computers to handle negative numbers efficiently and simplifies the process of arithmetic operations in binary.