Data Representation
Fixed Point

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:

  1. A binary point at the extreme left of the register to make the stored number a fraction.
  2. 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:

  1. Signed-magnitude representation
  2. Signed-1's complement representation
  3. 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:

  • +14+14: 0000111000001110
  • 14-14: 1000111010001110

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:

  • +14+14: 0000111000001110
  • 14-14: 1111000111110001

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:

  • +14+14: 0000111000001110
  • 14-14: 1111001011110010

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:

  1. Add the two numbers, including their sign bits.
  2. Discard any carry out of the sign (leftmost) bit position.

Examples:

  1. +6++13+6 + +13:
    • 00000110+00001101=0000111100000110 + 00001101 = 00001111
  2. +6+13+6 + -13:
    • 00000110+11110011=1111101000000110 + 11110011 = 11111010

Subtraction in Signed-2's Complement System

Subtraction of two signed binary numbers when negative numbers are in 2's complement form:

  1. Take the 2's complement of the subtrahend (including the sign bit).
  2. Add it to the minuend (including the sign bit).
  3. Discard any carry out of the sign bit position.

Example:

  • (6)(13)(-6) - (-13):
    • 111110101111001111111010 - 11110011 becomes 11111010+00001101=10000011111111010 + 00001101 = 100000111 (discard carry) = 0000011100000111

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:

  • 43854385 in BCD: 01000011100001010100 0011 1000 0101

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:

  • (+375)+(240)(+375) + (-240):
    • 03750 375: 00000011011101010000 0011 0111 0101
    • 97609 760: 10010111011000001001 0111 0110 0000
    • Sum: 00000001001101010000 0001 0011 0101 (end carry discarded) = +135135

Subtraction of decimal numbers in BCD is done by taking the 10's complement of the subtrahend and adding it to the minuend.