Representation of Signed Numbers and Fixed-Point Arithmetic
Signed Number Representation
In computing, positive integers including zero can be represented as unsigned numbers. To represent negative integers, however, we need a notation for negative values. In traditional arithmetic, a negative number is indicated by a minus sign and a positive number by a plus sign. Computers, due to hardware limitations, must represent everything with 1's and 0's, including the sign of a number. Consequently, it is customary to represent the sign with a bit placed in the leftmost position of the number. The convention is to make the sign bit equal to 0 for positive and to 1 for negative.
Fixed-Point Representation
In addition to the sign, a number may have a binary (or decimal) point. The position of the binary point is needed to represent fractions, integers, or mixed integer-fraction numbers. The representation of the binary point in a register is complicated by the fact that it is characterized by a position in the register. There are two ways of specifying the position of the binary point in a register: by giving it a fixed position or by employing a floating-point representation.
The fixed-point method assumes that the binary point is always fixed in one position. The two positions most widely used are:
- A binary point at the extreme left of the register to make the stored number a fraction.
- A binary point at the extreme right of the register to make the stored number an integer.
In either case, the binary point is not actually present but its presence is assumed from the fact that the number stored in the register is treated as a fraction or as an integer.
Floating-Point Representation
The floating-point representation uses a second register to store a number that designates the position of the binary point in the first register.
Integer Representation
When an integer binary number is positive, the sign is represented by 0 and the magnitude by a positive binary number. When the number is negative, the sign is represented by 1 but the rest of the number may be represented in one of three possible ways:
- Signed-magnitude representation
- Signed-1's complement representation
- Signed-2's complement representation
Signed-Magnitude Representation
The signed-magnitude representation of a negative number consists of the magnitude and a negative sign. For example, consider the signed number 14 stored in an 8-bit register:
- :
- :
Signed-1's Complement Representation
The signed-1's complement representation of a negative number is obtained by complementing all the bits of its positive value:
- :
- :
Signed-2's Complement Representation
The signed-2's complement representation is obtained by taking the 2's complement of the positive number, including its sign bit:
- :
- :
Arithmetic Operations
Addition in Signed-2's Complement System
The addition of two numbers in the signed-2's complement system does not require comparison or subtraction, only addition and complementation. The procedure is simple:
- Add the two numbers, including their sign bits.
- Discard any carry out of the sign (leftmost) bit position.
Examples:
- :
- :
Subtraction in Signed-2's Complement System
Subtraction of two signed binary numbers when negative numbers are in 2's complement form:
- Take the 2's complement of the subtrahend (including the sign bit).
- Add it to the minuend (including the sign bit).
- Discard any carry out of the sign bit position.
Example:
- :
- becomes (discard carry) =
Overflow Detection
When adding two n-bit numbers, an overflow occurs if the sum exceeds n bits. In signed addition, an overflow may occur if both numbers are positive or both are negative. Overflow can be detected by checking the carry into and out of the sign bit. If these two carries are not equal, an overflow condition is produced.
Decimal Fixed-Point Representation
Binary-Coded Decimal (BCD)
A 4-bit decimal code requires four flip-flops for each decimal digit. For example, the number 4385 in BCD requires 16 flip-flops:
- in BCD:
Signed BCD Representation
The sign of a decimal number is usually represented with four bits to conform with the 4-bit code of the decimal digits. It is customary to designate a plus with four 0's and a minus with the BCD equivalent of 9, which is 1001.
Arithmetic in BCD
Addition in the signed-10's complement system is done by adding all digits, including the sign digit, and discarding the end carry. For example:
- :
- :
- :
- Sum: (end carry discarded) = +
Subtraction of decimal numbers in BCD is done by taking the 10's complement of the subtrahend and adding it to the minuend.