Unit -3 : Computer Arithmetic

Binary numeral system (base2 number system) is

  • numeric values using 2 symbols: 0 &1
  • a positional notation with a radix of 2

Example of binary number and integers:

Integer

Binary Number

0

02

1

12

2

102

3

112

4

1002

5

1012

6

1102

7

1112

8

10002

9

10012

10

10102

11

10112

12

11002

13

11012

14

11102

15

11112

16

100002

Decimal basic concepts:

Decimal is base 10.

There are 10 digits in counting (0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

When you reach 10, you carry “1” over to the next column (left side).

The number after 9 is 10.

Binary basic concept:

Decimal base is 2.

There are 2 digits in counting (0, 1).

When you reach 2, you carry “1” over to the next column (left side).

We beginning with single digit, counting proceeds through each symbol in ascending order using only 0 &1. When the first digit is exhausted, next higher digit (to left) is incremented and counting start over at 0.

0000

0001

0010, 0011

0100, 0101, 0111

1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111

In binary system, each digit represents an increase of power of 2, therefore rightmost digit is 20, follow by 21, 22, 23….To determine the decimal representation of binary number, we sum up product at binary digit and power 2 which they represent.

Example 1 :

100110112 = (20*1) + (21*1) + (23*1) + (24*1) + (27*1) =155

Multiplication algorithm –Booth’s algorithm is a multiplication algorithm that multiplies two signed binary numbers in 2’s compliment notation.

Booth Multiplication Algorithm
Booth Multiplication Algorithm
Booth Multiplication Algorithm
Booth Multiplication Algorithm

Restoring Division Algorithm For Unsigned Integer

A division algorithm provides a quotient and a remainder when we divide two number. They are generally of two type slow algorithm and fast algorithm. Slow division algorithm are restoring, non-restoring, non-performing restoring, SRT algorithm and under fast comes Newton–Raphson and Goldschmidt.

In this article, will be performing restoring algorithm for unsigned integer. Restoring term is due to fact that value of register A is restored after each iteration.

Here, register Q contain quotient and register A contain remainder. Here, n-bit dividend is loaded in Q and divisor is loaded in M. Value of Register is initially kept 0 and this is the register whose value is restored during iteration due to which it is named Restoring.

Let’s pick the step involved:

  • Step-1: First the registers are initialized with corresponding values (Q = Dividend, M = Divisor, A = 0, n = number of bits in dividend)
  • Step-2: Then the content of register A and Q is shifted left as if they are a single unit
  • Step-3: Then content of register M is subtracted from A and result is stored in A
  • Step-4: Then the most significant bit of the A is checked if it is 0 the least significant bit of Q is set to 1 otherwise if it is 1 the least significant bit of Q is set to 0 and value of register A is restored i.e the value of A before the subtraction with M
  • Step-5: The value of counter n is decremented
  • Step-6: If the value of n becomes zero we get of the loop otherwise we repeat from step 2
  • Step-7: Finally, the register Q contain the quotient and A contain remainder

Examples:

Introduction of Floating Point Representation

1. To convert the floating point into decimal, we have 3 elements in a 32-bit floating point representation:
    i) Sign
    ii) Exponent
    iii) Mantissa

  • Sign bit is the first bit of the binary representation. ‘1’ implies negative number and ‘0’ implies positive number.
    Example: 11000001110100000000000000000000 This is negative number.
  • Exponent is decided by the next 8 bits of binary representation. 127 is the unique number for 32 bit floating point representation. It is known as bias. It is determined by 2k-1 -1 where ‘k’ is the number of bits in exponent field.There are 3 exponent bits in 8-bit representation and 8 exponent bits in 32-bit representation.
    Thus
    bias = 3 for 8 bit conversion (23-1 -1 = 4-1 = 3)
    bias = 127 for 32 bit conversion. (28-1 -1 = 128-1 = 127)
  • Example: 01000001110100000000000000000000
    10000011 = (131)10
    131-127 = 4Hence the exponent of 2 will be 4 i.e. 24 = 16.
  • Mantissa is calculated from the remaining 23 bits of the binary representation. It consists of ‘1’ and a fractional part which is determined by:
  • Example:01000001110100000000000000000000
  • The fractional part of mantissa is given by:1*(1/2) + 0*(1/4) + 1*(1/8) + 0*(1/16) +……… = 0.625Thus the mantissa will be 1 + 0.625 = 1.625The decimal number hence given as: Sign*Exponent*Mantissa = (-1)*(16)*(1.625) = -26

2. To convert the decimal into floating point, we have 3 elements in a 32-bit floating point representation:
    i) Sign (MSB)
    ii) Exponent (8 bits after MSB)
    iii) Mantissa (Remaining 23 bits)

  • Sign bit is the first bit of the binary representation. ‘1’ implies negative number and ‘0’ implies positive number.
    Example: To convert -17 into 32-bit floating point representation Sign bit = 1
  • Exponent is decided by the nearest smaller or equal to 2n number. For 17, 16 is the nearest 2n. Hence the exponent of 2 will be 4 since 24 = 16. 127 is the unique number for 32 bit floating point representation. It is known as bias. It is determined by 2k-1 -1 where ‘k’ is the number of bits in exponent field.Thus bias = 127 for 32 bit. (28-1 -1 = 128-1 = 127)Now, 127 + 4 = 131 i.e. 10000011 in binary representation.
  • Mantissa: 17 in binary = 10001.Move the binary point so that there is only one bit from the left. Adjust the exponent of 2 so that the value does not change. This is normalizing the number. 1.0001 x 24. Now, consider the fractional part and represented as 23 bits by adding zeros.00010000000000000000000