Module2
Module2
Example −Assume number is using 32-bit format which reserve 1 bit for the sign, 15 bits
for the integer part and 16 bits for the fractional part.
the Fractional part of the number is multiplied by the base of the new number system:
0. 625*2
1 .25*2
0 .5*2
1 .0*2
the result of the conversion was: 0.62510 = 0.1012
Adder
The hardware circuit which executes this addition is called Adder. There are two types of
adders namely Half adder and Full adder. Basic adder circuit does 1-bit addition and is
extended for n-bit addition. The adder circuit characteristics are detailed by a circuit, a truth
table, Formula and a block symbol. The adder circuits are constructed from logic gates which
satisfy the formula as per truth table. These are also called combinational logic. A
Combinational logic output reflects the input without clocking.
Figure Half adder
The Half Adder (HA) has two inputs (A, B) and two outputs (Sum and Carry). The Sum is
XOR of input while the Carry is AND of the input. The Half Adder is detailed in figure.
A Full Adder (FA) also performs 1-bit addition but taking 3 inputs (A, B and C i) and produces
two outputs (Sum and Carry). Like HA, FA generates result consisting of Sum (S) and Carry
out (Cout). Cout is used as Ci+1 while cascading for multiple bits of a word. Full Adder is
detailed in figure 8.3. A full adder can also be constructed using half adder blocks as in figure
Subtraction
Subtraction is finding the difference of B from A i.e A-B. Basis of binary subtraction is:
0-0=0
0 - 1 = -1
1-0=1
1-1=0
Of course, the usual borrow logic from the adjacent digit is applied as in the case of decimal
numbers. Examples of signed binary Subtraction is as below:
Flowchart of Multiplication:
Run of 1's
Based on the run status, the operation to be performed in the multiplication process is defined
as in table 9.2. The values of the current bit (Q0) and the outgoing bit (Qe) of the multiplier
decide the operation to be performed. By this, the multiplication is achieved in less number of
cycles based on the multiplier. A multiplier may have many combinations of runs based on its
value. This algorithm is sensitive to bit patterns of Multiplier. A pattern like 01010101 may
be the worse as it has many begin and end runs necessitating as many additions and
subtractions and may not save cycle time. But by and large Booth’s algorithm saves cycles.
Table 9.2 Booth Encoding for Multiplication – Operation regarding the run
Floating-Point Representation
This representation does not reserve a specific number of bits for the integer part or the
fractional part. Instead, it reserves a certain number of bits for the number (called the
mantissa or significand) and a certain number of bits to say where within that number the
decimal place sits (called the exponent).
Example: Suppose number is using 32-bit format: the 1 bit sign bit, 8 bits for signed
exponent, and 23 bits for the fractional part. The leading bit 1 is not stored (as it is always 1
for a normalized number) and is referred to as a “hidden bit”.
Then −53.5 is normalized as -53.5=(-110101.1)2=(-1.101011)x25 , which is represented as
following below,
Real numbers
Real numbers are numbers that include fractions/values after the decimal point.
For example, 123.75 is a real number.
Floating point representation
Real numbers are stored in a computer as floating point numbers using a mantissa (m),
a base (b) and an exponent (e) in this format:
m X be
Example (in decimal)
This example gives a general idea of the role of the mantissa, base and exponent. It does not
fully reflect the computer's method for storing real numbers.
The number 123.75 can be represented as a floating point number. To do this, move all the
digits so that the most significant digit is to the right of the decimal point:
123.75 → 0.12375
The number after the decimal point is the mantissa (m).
As this number is written in decimal (denary), the base (b) is 10 .
To work out the exponent (e) count how many decimal places you have moved the decimal
point by (in this case three). So we can represent 123.75 in floating point representation as
this:
0.12375 x 103
Example (in binary)
In the Higher course, all floating point representation is in binary.
First convert 123.75 to binary:
64 32 16 8 4 2 1 0.5 0.25
1 1 1 1 0 1 1 1 1
64 + 32 + 16 + 8 + 2 + 1 + 0.5 + 0.25 = 1111011.11
123.75 in binary is 1111011.11
Key fact
The computer will not store the actual decimal point as part of the floating point
number but it is used here for illustrative purposes.
To find the mantissa, move the decimal point to the right of the most significant bit of the
mantissa:
1111011.11 → 0.111101111
To calculate the exponent, count how many places the decimal point moved to give the
mantissa. In this case the decimal point moved seven places to the left:
So the exponent for our number is 7.
4 2 1
1 1 1
In binary, the number 7 is 111 as 4 + 2 + 1 = 7
In order to represent 123.75 the mantissa would be 111101111 and the exponent would be
111. This can be thought of as:
0.111101111 x 2111
Sign bit
As well as the mantissa, base and exponent, we have a digit before the decimal point. This is
used as a sign bit and is represented in binary as a 0 for positive and a 1 for negative.
How many bits?
There will always be a trade-off between accuracy and range when using floating point
notation, as there will always be a set number of bits allocated to storing real numbers:
increasing the number of bits devoted to the mantissa will improve the accuracy of a
floating point number
increasing the number of bits devoted to the exponent will increase the range of
numbers that can be held
In the Higher course, floating point numbers are represented as follows:
1 bit for the sign
15 bits for the mantissa
8 bits for the exponent
The value of AQ(here in this step, A and Q will be treated as a single unit) will
shift to the left.
In this step, subtraction occurs. M will be subtracted from A, and A will store the
result.
In this step, we check for the most significant bit of A. Suppose the most significant
bit in A is 1 after the above three stages in the restoring division algorithm. In that
case, it will set the least significant bit of Q as 0, and the value of A will again become
what it was before the subtraction operation in step 3. If the most significant bit in A is
0, then it will set the least significant bit of Q as 1.
N is decreased by 1 in this step.
In this step, we check the value of N. If the value of N becomes 0, we break the loop
here or move back to step 2.
In this step, we have our answer with the quotient in Q and the remainder in A.
N M A Q Operation
1101 A= A-M
1110 A=A-M
0000 A=A-M
1110 A=A-M
We got the quotient as 0010, which is 2, and the remainder as 0001, which is 1.
Let the dividend be 1011(11)=Q and the divisor 0011(3)=M. -M=1101
N M A Q Operation
1110 A= A-M
1111 A=A-M
0010 A=A-M
0010 A=A-M
We got the quotient as 0011, which is 3, and the remainder as 0010, which is 2.