Mechatronics: Number systems
By: D Mokwele
Objectives
•
be familiar with the Characteristics of a Number system
•
know the Decimal Number System
•
know the Binary Number System
•
Understand why we need a Binary Number System
•
know the Hexadecimal Number System
•
understand BCD Numbers
•
know about different Data Types
•
understand Boolean and Integer Data Types
Faculty of Engineering and the Built Environment
Department of Mechanical and Mechatronics Engineering)
What is a number system?
• Computers understand Machine language
• Code created on computer
• is converted into machine language
• Machine language
• Comprise of numbers
• Number system
• System to represent numbers
Faculty of Engineering and the Built Environment
Department of Mechanical and Mechatronics Engineering)
Faculty of Engineering and the Built Environment
Department of Mechanical and Mechatronics Engineering)
Characteristics of a Number System
Digit
e.g. 0,1,2,3,4,5,6,7,8,9
Base
e.g. 10
Positional Weight
e.g. ...100,10,1
Decimal System
Digits:
Base:
Positional Weight:
Example:
100 = 1
101 = 10
102 = 100
103 = 1000
etc.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
10
Powers of Base 10
205
5x
1 =
5
0 x 10 =
0
2 x 100 = 200
205
Binary System
Digits:
Base:
Positional Weight:
0, 1
2
Powers of Base 2
128 64 32 16
Example:
20 = 1
21 = 2
22 = 4
23 = 8
24 = 16
25 = 32
26 = 64
27 = 128
etc.
8
4
2
1
11001101
1 x 1
0 x 2
1 x 4
1 x 8
0 x 16
0 x 32
1 x 64
1 x 128
=
1
=
0
=
4
=
8
=
0
=
0
= 64
= 128
205
Why do we need a Binary System?
Input
S1
5V
Output
L1
Because electronic circuits can only generate or recognize either a 0 or a 1
The lamp can be in one of 2 states: Either OFF or ON.
Hexadecimal System
Digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Positional Weight:
Base:
16
Powers of Base 16
Example:
160 = 1
161 = 16
162 = 256
163 = 4096
etc.
9F
15 x 1 = 15
9 x 16 = 144
159
Binary, Decimal and Hex table
BCD Numbers
0
2
0
5
0000
0010
0000 0101
x 103
x 102
x 101
x 100
Data Types
Data type
Description
WORD; DWORD Binary: 16 bits; 32 bits
BOOL
Boolean value, 1 bit (true = 1, false = 0)
BYTE; WORD
Hexadecimal: 8 bits; 16 bits
INT
IEC Integer format: 16 bits,
1 sign bit + 15 bits
REAL
IEC Real number format (floating-point
number): 32 bits
Counter constant: 16 bits (BCD format)
WORD
Data Types: Boolean and Integer
1
true = 1, or false = 0
Data Type BOOLEAN
15
0
0
0
0
0
0
0
8
7
0
1
0
1
Decimal value: 128+64
Sign bit
0
0
+
Data Type INTEGER
1
1
0
1
8 + 4
+
1
= 205
Answer the following questions
1. Name the 3 characteristics of a Number System
2. What are these characteristics for the Decimal Number System?
3. What are these characteristics for the Binary Number System?
4. What are these characteristics for the Hexadecimal Number System?
5. Why do we need a Binary Number System?
Answer the following questions
6. Draw a table that lists Binary, Decimal and Hexadecimal numbers
from 0 to 15
(Fill in the Binary and Hexadecimal values in the table below)
Answer the following questions
7. Convert 20510 to BCD
8. Convert 101101112 to Decimal
9. Convert 101101112 to Hexadecimal
10. How many bits is a BOOL ?
11. How many bits is a BYTE ?
12. How many bits is a WORD ?
13. How many bits is a DOUBLEWORD ?
14. The INT data type occupies _____ Bits ?
15. The REAL data type occupies _____ Bits ?
16. Bit 15 in an INT data type is the ______ Bit ?