s e f
0 10000000 (1)001 0000 0000 0000 0000 0000
or, the required 32-bit floating point number is:
01000000000100000000000000000000
Example 1.35
Convert the decimal number 134.0625 10into floating point.
Solution 1.35
Write the number in binary:
134.0625 10= 10000110.0001
Normalize the number:
10000110.0001 = 1.00001100001 × 2 7
Here, s = 0, e – 127 = 7 or e = 134, and f = 00001100001000000000000.
The required floating point number can be written as:
s e f
0 10000110 (1)00001100001000000000000
or, the required 32-bit floating point number is:
01000011000001100001000000000000
1.22.3 Multiplication and Division of Floating Point Numbers
Multiplication and division of floating point numbers are rather easy. Here are the steps:
• Add (or subtract) the exponents of the numbers.
• Multiply (or divide) the mantissa of the numbers.
• Correct the exponent.
• Normalize the number.
• The sign of the result is the EXOR of the signs of the two numbers.
Since the exponent is processed twice in the calculations, we have to subtract 127 from the exponent.
An example showing the multiplication of two floating point numbers follows.
Example 1.36
Show the decimal numbers 0.5 10and 0.75 10in floating point and then calculate their multiplication.
Solution 1.36
Convert the numbers into floating point as:
0.5 10= 1.0000 × 2 -1
here, s = 0, e – 127 = -1 or e = 126 and f = 0000
or,
0.5 10= 0 01110110 (1)000 0000 0000 0000 0000 0000
Similarly,
0.75 10= 1.1000 × 2 -1
here, s = 0, e = 126 and f = 1000
or,
0.75 10= 0 01110110 (1)100 0000 0000 0000 0000 0000
Multiplying the mantissas results in “(1)100 0000 0000 0000 0000 0000.” The sum of the exponents is 126+126=252. Subtracting 127 from the mantissa, we obtain 252–127=125. The EXOR of the signs of the numbers is 0. Thus, the result can be shown in floating point as:
0 01111101 (1)100 0000 0000 0000 0000 0000
This number is equivalent to decimal 0.375 (0.5×0.75=0.375), which is the correct result.
1.22.4 Addition and Subtraction of Floating Point Numbers
The exponents of floating point numbers must be the same before they can be added or subtracted. The steps to add or subtract floating point numbers are:
• Shift the smaller number to the right until the exponents of both numbers are the same. Increment the exponent of the smaller number after each shift.
• Add (or subtract) the mantissa of each number as an integer calculation, without considering the decimal points.
• Normalize the result.
An example follows.
Example 1.37
Show decimal numbers 0.5 10and 0.75 10in floating point and then calculate the sum of these numbers.
Solution 1.37
As shown in Example 1.36, we can convert the numbers into floating point as:
0.5 10= 0 01110110 (1)000 0000 0000 0000 0000 0000
Similarly,
0.75 10= 0 01110110 (1)100 0000 0000 0000 0000 0000
Since the exponents of both numbers are the same, there is no need to shift the smaller number. If we add the mantissa of the numbers without considering the decimal points, we get:
(1)000 0000 0000 0000 0000 0000
+ (1)100 0000 0000 0000 0000 0000
--------------------------------
(10)100 0000 0000 0000 0000 0000
To normalize the number, shift it right by one digit and then increment its exponent. The resulting number is:
0 01111111 (1)010 0000 0000 0000 0000 0000
This floating point number is equal to decimal number 1.25, which is the sum of decimal numbers 0.5 and 0.75.
A program for converting floating point numbers into decimal, and decimal numbers into floating point, is available for free on the following web site:
http://babbage.cs.qc.edu/courses/cs341/IEEE-754.html
BCD (binary coded decimal) numbers are usually used in display systems such as LCDs and 7-segment displays to show numeric values. In BCD, each digit is a 4-bit number from 0 to 9. As an example, Table 1.4 shows the BCD numbers between 0 and 20.
Table 1.4: BCD numbers between 0 and 20
Decimal |
BCD |
Binary |
0 |
0000 |
0000 |
1 |
0001 |
0001 |
2 |
0010 |
0010 |
3 |
0011 |
0011 |
4 |
0100 |
0100 |
5 |
0101 |
0101 |
6 |
0110 |
0110 |
7 |
0111 |
0111 |
8 |
1000 |
1000 |
9 |
1001 |
1001 |
10 |
0001 0000 |
1010 |
11 |
0001 0001 |
1011 |
12 |
0001 0010 |
1100 |
13 |
0001 0011 |
1101 |
14 |
0001 0100 |
1110 |
15 |
0001 0101 |
1111 |
16 |
0001 0110 |
1 0000 |
17 |
0001 0111 |
1 0001 |
18 |
0001 1000 |
1 0010 |
19 |
0001 1001 |
1 0011 |
20 |
0010 0000 |
1 0100 |
Example 1.38
Write the decimal number 295 as a BCD number.
Solution 1.38
Write the 4-bit binary equivalent of each digit:
2 = 0010 29 = 1001 25 = 0101 2
The BCD number is 0010 1001 0101 2.
Example 1.39
Write the decimal equivalent of BCD number 1001 1001 0110 0001 2.
Solution 1.39
Writing the decimal equivalent of each group of 4-bit yields the decimal number: 9961
Chapter 1 has provided an introduction to the microprocessor and microcontroller systems. The basic building blocks of microcontrollers were described briefly. The chapter also provided an introduction to various number systems, and described how to convert a given number from one base into another. The important topics of floating point numbers and floating point arithmetic were also described with examples.
1. What is a microcontroller? What is a microprocessor? Explain the main difference between a microprocessor and a microcontroller.
2. Identify some applications of microcontrollers around you.
3. Where would you use an EPROM memory?
4. Where would you use a RAM memory?
5. Explain the types of memory usually used in microcontrollers.
6. What is an input-output port?
7. What is an analog-to-digital converter? Give an example of how this converter is used.
8. Explain why a watchdog timer could be useful in a real-time system.
9. What is serial input-output? Where would you use serial communication?
10. Why is the current sink/source capability important in the specification of an output port pin?
11. What is an interrupt? Explain what happens when an interrupt is recognized by a microcontroller?
12. Why is brown-out detection important in real-time systems?
13. Explain the difference between an RISC-based microcontroller and a CISC-based microcontroller. What type of microcontroller is PIC?
14. Convert the following decimal numbers into binary:
Читать дальше