DLDCA Module 6 2023
DLDCA Module 6 2023
DLDCA Module 6 2023
Module 6
Data Representation and Arithmetic Algorithm
Motivation:
Computer understands only binaries i.e. 0 or 1. The ALU computations also will be carried out
internally in the form of binary numbers by making use of algorithms. Hence there is a need to
understand the different number representations and the arithmetic algorithms. This gives the
understanding of how arithmetic calculations are done by the computer.
Syllabus:
Lecture Content Duration Self-Study
no (Hr) (Hrs)
1 Signed number representation 1 1
2 Fixed point computation algorithms 1 1
3 Booth multiplication 1 2
4 Non-restoring Division 1 2
5 Restoring Division 1 2
6 Floating point arithmetic algorithms 1 2
7 IEEE 754 floating point number representation 1 2
Learning Objectives:
Learners shall be able to:
● To explain the different number representations
● To describe the arithmetic algorithms for fixed point numbers
● To compute the multiplication of two numbers using Booth multiplication
● To compute the division of two numbers using no-restoring and restoring division algorithms
● To describe the Floating point arithmetic algorithms
● To explain about IEEE 754 floating point number representation
2
Theoretical Background:
Data is manipulated by using the arithmetic instructions in digital computers. Data is manipulated to
produce results necessary to give solution for the computation problems. The Addition, subtraction,
multiplication and division are the four basic arithmetic operations. If we want then we can derive
other operations by using these four operations. To execute arithmetic operations there is a separate
section called arithmetic processing unit in central processing unit. The arithmetic instructions are
performed generally on binary or decimal data. Fixed-point numbers are used to represent integers
or fractions. We can have signed or unsigned negative numbers. Fixed-point addition is the simplest
arithmetic operation. If we want to solve a problem then we use a sequence of well-defined steps.
These steps are collectively called algorithm. To solve various problems we give algorithms. In order
to solve the computational problems, arithmetic instructions are used in digital computers that
manipulate data. These instructions perform arithmetic calculations. And these instructions perform
a great activity in processing data in a digital computer. With the four basic arithmetic operations
addition, subtraction, multiplication and division, it is possible to derive other arithmetic operations
and solve scientific problems by means of numerical analysis methods. A processor has an arithmetic
processor (as a sub part of it) that executes arithmetic operations. The data type, assumed to reside in
processor, registers during the execution of an arithmetic instruction. Negative numbers may be in a
signed magnitude or signed complement representation. There are three ways of representing
negative fixed point - binary numbers signed magnitude, signed 1’s complement or signed 2’s
complement. Most computers use the signed magnitude representation for the mantissa.
Key Definitions:
Half adder: This is a logic circuit which performs the addition of two binary digits and produces a
sum and a carry output.
Full adder: This is a logic circuit which performs addition of three bits (two significant bits and a
previous carry) and produces a sum and a carry output.
Ripple carry adder: This can be constructed using a number of full adder circuits connected in
parallel. The carry output of each adder is connected to the carry output of the next higher-order
adder. Either a half-adder can be used for the least significant position or the carry input of a full
adder is made 0 because there is no carry into the least significant position
Mantissa underflow: In the process of aligning mantissa, digits may flow off the right end of the
mantissa. In such case truncation methods are used.
3
Mantissa overflow: The addition of two mantissas of the same sign may result in a carryout of the
most significant bit. If so, the mantissa is shifted right and the exponent is incremented.
Exponent underflow: This occurs when a negative exponent exceeds the maximum possible
exponent value. In such cases, the number is designated as zero.
Exponent overflow: This occurs when a positive exponent exceeds the maximum possible exponent
value. In some systems this may be designated as +∞ or -∞.
Guard bits: These are extra bits provided in the intermediate steps of floating-point arithmetic
calculations in order to get maximum accuracy in the final result.
Arithmetic Logic Unit (ALU): It is a digital circuit that performs arithmetic and logical operations.
The ALU is a fundamental building block of the central processing unit (CPU) of a computer.
Accumulator: It is a special storage register associated with the arithmetic logic unit for storing the
results of steps in a calculation or data transfer.
Arithmetic Operator: It is the arithmetical signs of addition, subtraction, division and multiplication
as used by a given programming language.
Central Processing Unit (CPU): It is the main part of the computer, its 'brain', consisting of the
central memory, arithmetic logic unit and control unit.
Control Unit (CU): It is that part of the computer which accesses instructions in sequence, interprets
them and then directs their implementation.
Course Content:
Lecture 1
Variables such as integers can be represented in two ways, i.e., signed and unsigned. Signed numbers
use sign flag to distinguish between negative values and positive values. Number representation
techniques like: Binary, Octal, Decimal and Hexadecimal number representation techniques can
represent numbers in both signed and unsigned ways. Binary Number System is one the type of
Number Representation techniques. It is most popular and used in digital systems. Binary system is
used for representing binary quantities which can be represented by any device that has only two
operating states or possible conditions. For example, a switch has only two states: open or close.
4
In the Binary System, there are only two symbols or possible digit values, i.e., 0 and 1. Represented
by any device that only 2 operating states or possible conditions. Binary numbers are indicated by the
addition of either an 0b prefix or a 2 suffix.
Representation of Binary Numbers:
Binary numbers can be represented in signed and unsigned way. Unsigned binary numbers do not
have sign bit, whereas signed binary numbers uses signed bit as well or these can be distinguishable
between positive and negative numbers. A signed binary is a specific data type of a signed variable.
Example-2: Find range of 5 bit unsigned binary numbers. Also, find minimum and maximum value
in this range.
Since, range of unsigned binary number is from 0 to (2n-1). Therefore, range of 5 bit unsigned binary
number is from 0 to (25-1) which is equal from minimum value 0 (i.e., 00000) to maximum value 31
(i.e., 11111).
2. Signed Numbers:
Signed numbers contain sign flag, this representation distinguish positive and negative numbers.
This technique contains both sign bit and magnitude of a number. For example, in representation of
negative decimal numbers, we need to put negative symbol in front of given decimal number.
For example, range of 6 bit Sign-Magnitude form binary number is from (25-1) to (25-1) which is equal
from minimum value -31 (i.e., 1 11111) to maximum value +31 (i.e., 0 11111). And zero (0) has two
representation, -0 (i.e., 1 00000) and +0 (i.e., 0 00000).
2.(b) 1’s complement form:
Since, 1’s complement of a number is obtained by inverting each bit of given number. So, we
represent positive numbers in binary form and negative numbers in 1’s complement form. There is
extra bit for sign representation. If value of sign bit is 0, then number is positive and you can directly
represent it in simple binary form, but if value of sign bit 1, then number is negative and you have to
take 1’s complement of given binary number. You can get negative number by 1’s complement of a
positive number and positive number by using 1’s complement of a negative number. Therefore, in
this representation, zero (0) can have two representations, that’s why 1’s complement form is also
ambiguous form. The range of 1’s complement form is from (2(n-1)-1) to (2(n-1)-1).
For example, range of 6 bit 1’s complement form binary number is from (25-1) to (25-1) which is equal
from minimum value -31 (i.e., 1 00000) to maximum value +31 (i.e., 0 11111). And zero (0) has two
representation, -0 (i.e., 1 11111) and +0 (i.e., 0 00000).
2.(c) 2’s complement form:
Since, 2’s complement of a number is obtained by inverting each bit of given number plus 1 to least
significant bit (LSB). So, we represent positive numbers in binary form and negative numbers in 2’s
complement form. There is extra bit for sign representation. If value of sign bit is 0, then number is
positive and you can directly represent it in simple binary form, but if value of sign bit 1, then
number is negative and you have to take 2’s complement of given binary number. You can get
negative number by 2’s complement of a positive number and positive number by directly using
simple binary representation. If value of most significant bit (MSB) is 1, then take 2’s complement
from, else not. Therefore, in this representation, zero (0) has only one (unique) representation which
is always positive. The range of 2’s complement form is from (2(n-1)) to (2(n-1)-1).
For example, range of 6 bit 2’s complement form binary number is from (2 5) to (25-1) which is equal
from minimum value -32 (i.e., 1 00000) to maximum value +31 (i.e., 0 11111). And zero (0) has two
representation, -0 (i.e., 1 11111) and +0 (i.e., 0 00000).
c) Sign Magnitude
d) Encode
2) The 1’s complement of 1 in 4 bits is __________
a) 0001
b) 0
c) 1001
d) 1110
3) The binary number 111 in its 2’s complement form is ____________
a) 010
b) 001
c) 000
d) 111
4) The carry generation function: ci + 1 = yici + xici + xiyi, is implemented in ____________
a) Half adders
b) Full adders
c) Ripple adders
d) Fast adders
Exercise
Q.1 List the different ways of representing signed numbers.
Q.2 State the drawback of signed magnitude representation.
Q.3 Find the 2’s complement of 0101.
Q4. Explain two complement and one’s complement with examples.
Learning from this lecture: Learners will be able to understand different ways of representing
unsigned and signed numbers.
Lecture 2
A fixed-point number representation is a real data type for a number that has a fixed number of digits
after (and sometimes also before) the radix point (after the decimal point '.' in English decimal
notation). Fixed-point number representation can be compared to the more complicated (and more
computationally demanding) floating-point number representation. Fixed-point numbers are useful
for representing fractional values, usually in base 2 or base 10, when the executing processor has
no floating point unit (FPU) as is the case for older or low-
cost embedded microprocessors and microcontrollers.
1010
(×) 101
—————–
1010
0000
——————
01010 ……. First Intermediate Sum
1010
——————–
110010
Comparison with Decimal values:
10102 = 1010
10102 = 510
10 x 5 = 5010
(110010)2 = 5010
Another example of binary multiplication with a decimal point is as follows:
Example 2: 1011.01 × 110.1
Solution:
There are different ways to solve division problems using binary operations. Long division is one of
them and the easiest and the most efficient way.
The binary division is much easier than the decimal division when you remember the following
10
In the case of binary multiplication, since the digits are 0 and 1, each step of the multiplication is
simple. If the multiplier digit is 1, a copy of the multiplicand (1 × multiplicand) is placed in the
proper positions; if the multiplier digit is 0, a number of 0 digits (0 × multiplicand) are placed in the
proper positions.
Consider the multiplication of positive numbers. The first version of the multiplier circuit, which
implements the shift-and-add multiplication method for two n-bit numbers, is shown in Figure
Step A Q B Operation
Exercise
Q.1 What is a fixed-point number?
Q.2 Perform the following: i) 1100 + 0001 ii) 1100 - 0101
Q.3 Draw the block diagram of the basic multiplier circuit and explain.
Learning from this lecture: Learners will be get knowledge about the basic binary arithmetic
operations and the algorithm used for unsigned multiplication.
Lecture 3
Booth Multiplication
Learning objective:
In this lecture learners will able to understand the concept of Booth Multiplication.
There are many methods to multiply 2's complement numbers. The easiest is to simply find the
magnitude of the two multiplicands, multiply these together, and then use the original sign bits to
determine the sign of the result. If the multiplicands had the same sign, the result must be positive, if
they had different signs, the result is negative. Multiplication by zero is a special case (the result is
always zero, with no sign bit).
Booth’s Algorithm
● Booth's algorithm can be used to multiply two numbers represented using two's complement
(2C)
● Booth's algorithm will work for both positive and negative numbers represented using 2C
● The algorithm uses a combination of addition, subtraction and Arithmetic Right Shifts
–subtraction is performed by taking the two's complement of the subtrahend (the number to
be subtracted) and adding it to the minuend
Hardware Implementation
Booth's algorithm uses the following 4 registers (A, Q, Q-1)
● A– each bit in A is initialized to 0
- A is reused and eventually stores the most-significant bits of the result
- A is the same size as M
● Q is initialized to store the multiplier
- Q is reused and eventually stores the least-significant bits of the result
15
● Q-1 is initialized to 0
- this is placed to the right of Q
- this is a 1-bit register which remembers the least-significant bit of Q (Q0)
● M stores the multiplicand
1) What is the default value of accumulator in booth’s multiplication of two 4-bit binary numbers?
a) 0
b) 1
17
c) 0000
d) 00000
2) What will be the value obtained after multiplication of (-2) * (-3) using Booth’s Algorithm?
a) 6
b) -6
c) -2
d) -3
3) One extra bit is added on the left of a binary number, in case of Binary Multiplication using Booth’s
Algorithm.
a) True
b) False
Exercise
Q.1 Why Booth’s algorithm is used for binary multiplication?
Q.2 Draw the block diagram of Booth’s multiplier circuit and explain.
Q.3 Solve -2*4 using Booth multiplication.
Q.4 Solve -2*-4 using Booth multiplication.
Learning from this lecture: Learners will be able to understand the steps of Booth multiplication
algorithm in detail.
Lecture 4
Restoring Division
Learning objective:
In this lecture learners will able to understand the concept of Restoring Division.
else
}
Note: When A and Q are left shifted, the MSB of Q becomes the LSB of A, and the MSB of A is lost.
The LSB of Q is made available for the next quotient bit.
Flowchart of restoring division operation:
19
b) Divide 8 by 3
Initially, the divisor 3= (0011)2is in register M, the dividend 8= (1000)2is in register Q, and register A is
zero. Note that subtraction by 3= (0011)2is implemented by adding its 2's complement 1101.
20
Exercise
Q.1 Divide 110/10 using binary division rules.
Q.2 Draw the flowchart for restoring division method.
Q.3 Perform 6/3 using restoring division.
Learning from this lecture: Learners will be able to understand the concept of restoring
division method.
Lecture 5
Non-Restoring Division
Learning objective:
In this lecture learners will be able to understand the concept of Non-Restoring Division.
Algorithm:
S1: Do n times
If the sign of A is 0, shift A and Q left one binary position and subtract M from A; otherwise, shift
A and Q left and add M to A.
S2: If the sign of A is 1, add M to A.
The flowchart for non-restoring division is shown in figure 2.8.
22
Exercise
Q.1 Draw the block diagram for the hardware implementation of division.
Q.2 Draw the flowchart for non restoring division method.
Q.3 Perform -6/3 using restoring division.
Learning from this lecture: Learners will be able to understand the concept of non-restoring division
method.
Lecture 6
Floating point arithmetic algorithms
Learning objective:
In this lecture learners will able to understand the concept of Floating point arithmetic algorithms
3.52 x 103
+ 1.97 x 105
-----------------------------------------
1
0.0352 x 105
+ 1.97 x 105
-----------------------------------------
2.0052 x 105
Adjusting the mantissa and exponent is also sometimes necessary to normalize results. For example,
9.9 x 102 + 9.9 x 102 is 19.8 x 102, which must be normalized to 1.98 x 103.
A binary floating system stores a signed binary mantissa and a signed binary exponent, and usually
uses a radix of 2. Using a radix of 2 (or any power of 2) allows us to normalize and denormalize by
shifting the binary digits in the mantissa and adjusting the integer exponent on the radix of 2.(
Shifting binary digits in the mantissa n bits to the left or right multiplies or divides the mantissa by 2n.
)
000102 x 23 = 010002 x 21.
The standard floating point formats are defined by the IEEE society. The IEEE formats are slightly
more complex that necessary to understand floating point in general, so we will start with a simpler
example here.
ii. A Simple Floating Point Format
Suppose a 32-bit floating point format has a 24-bit two's complement mantissa, an 8-bit two's
complement exponent, and a radix of 2. The general structure is:
mantissa x 2exponent
Where mantissa is a 24-bit two's complement integer, and exponent is an 8-bit two's complement
integer.
The binary format is as follows:
Floating Point Format
Mantissa Exponent
24 bits, two's complement 8 bits, two's complement
26
Fig 2.10: Flowchart for floating point addition & subtraction operation
Algorithm
Declare registers:
AM [0 :M - 1] ; For mantissa of A
BM [0 :M - 1] ; For mantissa of B
AE [0 :E - 1] ; For exponent of A
BE [0 : E - 1] ; For exponent of B
E [0 : E - 1] ; For temporary storage of exponent
AE <- exponent of A
BE <- exponent of B
2) The decimal numbers represented in the computer are called as floating point numbers, as the
decimal point floats through the number.
a) True
b) False
3) ________ constitutes the representation of the floating number.
a) Sign
b) Significant digits
c) Scale factor
d) All of the mentioned
Exercise
Q.1 Describe the standard way of representing floating point numbers.
Q.2 Draw the flowchart for floating point addition and subtraction.
Q.3 List the problems encountered in floating point arithmetic.
Learning from this lecture: Learners will be able to understand the concept of floating point
number representation and the algorithm used for floating point arithmetic.
Lecture 7
IEEE 754 floating point number representation
Learning objective:
In this lecture learners will able to understand the concept of IEEE 754 floating point number
representation
S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF
01 89 31
Double Precision
The IEEE double precision floating point standard representation requires a 64 bit word, which may
be represented as numbered from 0 to 63, left to right. The first bit is the sign bit, S, the next eleven
bits are the exponent bits, 'E', and the final 52 bits are the fraction 'F':
S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
01 11 12 63
33
Example:
85.125
85 = 1010101
0.125 = 001
85.125 = 1010101.001
=1.010101001 x 2^6
sign = 0
1. Single precision:
biased exponent 127+6=133
133 = 10000101
Normalized mantissa = 010101001
we will add 0's to complete the 23 bits
Special Values: IEEE has reserved some values that cause ambiguity.
● Zero -
Zero is a special value denoted with an exponent and mantissa of 0. -0 and +0 are distinct values,
though they both are equal.
● Denormalised –
If the exponent is all zeros, but the mantissa is not then the value is a denormalized number. This
means this number does not have an assumed leading one before the binary point.
34
● Infinity –
The values +infinity and -infinity are denoted with an exponent of all ones and a mantissa of all
zeros. The sign bit distinguishes between negative infinity and positive infinity. Operations with
infinite values are well defined in IEEE.
Exercise
Q.1 Explain Single Precision IEEE 754 floating point representation.
Q.2 Explain Double Precision IEEE 754 floating point representation.
Q.3 Show the IEEE 754 representation of 10.4 in single precision and double precision format.
35
Learning from this lecture: Learners will be able to understand the concept of IEEE 754 floating
point number representations.
Conclusion
The study of Data representation and arithmetic algorithms helps to understand fixed-point and
floating-point number representations. Also this study helps to understand the multiplication and
division algorithms used by the ALU of the computer.
References:
1. William Stallings, “Computer Organization and Architecture: Designing for Performance”, Eighth
Edition, Pearson.
37
2. Carl Hamacher, Zvonko Vrasenic and Safwat Zaky, “Computer Organization”, Fifth edition, Tata
McGraw-Hill.
Self-assessment
Q.1) Write short note on fixed-point number representation.
Q.2) Write short note on floating-point number representation.
Q.3) Explain the algorithm for unsigned multiplication.
Q.4) Explain the algorithm for signed multiplication.
Q.5) Explain restoring division method.
Q.6) Explain Non-restoring division method.
Q.7) Describe IEEE 754 floating point number representation.
Self-evaluation
Name of
Student
Class
Roll No.
Subject
Module No.
S.No Tick
Your choice
1. Do you understand the fixed-point o Yes
number representation? o No
2. Do you understand the floating-point o Yes
number representation? o No
3. Do you understand the algorithms used o Yes
for binary multiplication and division? o No
4. Do you understand the difference between o Yes
restoring and non restoring division? o No
38