3.number System & Conversions
3.number System & Conversions
Prepared by:
Azad O. Abdullah
[email protected]
1
“Number Systems and
Conversions”
2
Contents:
Number Systems
Conversions
Arithmetic
3
Number Systems:
Decimal Numbers
Binary Numbers
Octal Numbers
Hexadecimal Numbers
4
Decimal Numbers:
5
Decimal Numbers:
Example 1: Express the decimal number 47 as a
sum of the values of each digit.
Solution: The digit 4 has a weight of 10, which is
101, as indicated its position. The Digit 7 has a
weight 100 , which is 100, as indicated by its
position.
Solution:
(92.53)10 = (9 X 101) + (2 X 100) + (5 X 10-1) + (3
X 10-2)
= (9 X 10) + (2 X 1) + (5 X 0.1) + (3 X 0.01)
= 90 + 2 + 0.5 + 0.03
= (92.53)10
7
Binary Numbers:
The binary number system is another way to
represent quantities.
It is less complicated than the decimal system
because it has only two digits.
The binary system with its two digits is a base-
two system.
The two binary digits (bits) are 1 and 0.
8
Ex1:
Ex2: (100101.01)2 = (?)10
=(1 X 25)+(0 X 24)+(0 X 23)+(1 X 22)+(0X 21)+
(1 X 20)+(0 X 2-1)+(1 X 2-2)
= 32 + 0 + 0 + 4 + 0 +1+ 0 + 0.25
=(37.25)10
Ex3: (101.011)2 = (?)10
=(1x22)+(0 x21)+(1x 20)+(0x2-1)+(1x2-2)+(1
x2-3)
=(1x4)+(0x2)+(1x1)+(0x0.5)+(1x0.25)+(1x
0.125)
= 4 + 0 + 1 + 0 + 0.25 + 0.125
= (5.375)10
Octal Number:
The octal number system is compose of eight digits,
which are 0,1,2,3,4,5,6, and 7
1. (2374)8
2. (607.17)8
3. (7016.074)8
12
Solutions:
= 1024+192+56+4
= (1276)10
=(391.234375)10
3 =(?)10
13
Hexadecimal Number:
It is base on 16 (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)
Example:
1. CD8.F14D
2. AF
3. C
4. (9)16
5. AA8.7
6. E6
14
Solutions:
1) CD8.F14D =(?)10
=(3288.94258117)10
2) AF=? H.W
3) C=(12)10
4) (9)10 =? H.W
15
5) Convert (E6)16 to Decimal.
=(2728.4375)10
Number Conversions:
Decimal-to-Decimal Conversion “proof”
Binary-to-Decimal Conversion Already studied:
Octal-to-Decimal Conversion * Base
Hexadecimal-to-Decimal Conversion
(10,2,8,16)=(…)10
Decimal-to-Binary Conversion Integer ( / , R , )
Decimal-to-Octal Conversion
Decimal-to-Hexadecimal Conversion
Point ( * , C , )
Binary-to-Octal Conversion
Octal-to- Binary Conversion 3 bits
Hexadecimal-to-Binary Conversion
Binary-to-Hexadecimal Conversion 4 bits
Hexadecimal-to-Octal Conversion 4 bits to 3 bits
Octal-to-Hexadecimal Conversion
3 bits to 4 bits
Note:
Any base-to-Decimal Conversion
17
Decimal-To-Binary Conversion:
Example 1: Convert from (205.188)10 to binary.
Solution: Number Base Remainder
205 2 1
0.188 x 2 = 0.376 carry = 0 LSB 102 2 0
25 2 1
0.752 x 2 = 1.504 carry = 1 12 2 0
(205.188)10=(11001101.00110 )2
18
Decimal-to-Octal Conversion:
Example1: Express (150)10 in octal
Solution: (150)10 = (226)8
R
150÷8 = 18 6 (LSB)
18 ÷ 8 = 2 2
2÷8=0 2 (MSB)
20
Binary-to-Octal Conversion:
Solution:
001 001 101 . 010 111
1 1 5 . 2 7
= (115.27)8
21
Octal-to-Binary Conversion:
Example2: Convert (625.13)8 to Binary.
Solution:
6 2 5 . 1 3
110 010 101 . 001 011
= (110010101. 001011)2
22
Hexadecimal-to-Binary Conversion:
23
Binary-to-Hexadecimal Conversion:
=(5B.C)16
Octal-to-Hexadecimal Conversion:
Ex:
(77743.654)8 = (?)16
Sol:
( 7 7 7 4 3 . 6 5 4 )8
= (7FE3.D60)16
Hexadecimal-to-Octal Conversion:
Ex:
(CED4.6F9A)16 = (?)8
Sol:
( 001 100 111 011 010 100 . 011 011 111 001 101 000 )2
( 1 4 7 3 2 4 . 3 3 7 1 5 0 )8
= (147324.337150)8
Any base-to-Decimal Conversion:
N=(a4a3a2a1a0.a-1a-2)R
= a4*R4 + a3*R3 + a2*R2 + a1*R1 + a0*R0 + a-1*R-1 + a-2*R-2
27
Numbers in All Different Bases:
(from 0 till 19)
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
28
Decimal Base=10 Binary Base=2 Octal Base=8 Hexadecimal Base=16
0,1,2,3,4,5,6,7,8,9 0,1 0,1,2,3,4,5,6,7 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
10 1010 12 A
11 01011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
16 1 0000 20 10
17 1 0001 21 11
18 1 0010 22 12
19 1 0011 23 13
29
Codes:
1.BCD Code:
It’scomposed of four bits representing the decimal digits
0 through 9.
For people used to dealing with the decimal system,
binary numbers are difficult to read.
For this reason , a more easily readable numeral
representation was introduced, i.e. the binary coded
decimal notation, the so-called BCD code (Binary Coded
Decimal).
With this BCD code, each individual digit of the decimal
number system is represented by a corresponding binary
number.
Each code has 4 binary bits
30
BCD-Decim al
10000110
86
Decim al-BCD
35
00110101
Decimal (Normal) Binary BCD
0 0000 0000
1 0001 0001
2 0010 0010
8 1000 1000
9 1001 1001
0011
Decimal
to
3 BCD
Encoder
34
2.Gray Code:
35
Binary To Gray
Down the first binary number and compare each one with the other. If
Same = 0 but Difference=1
Example: Convert the following binary numbers to Gray Code?
1. (1010110)2 ( ? )Gray Code
2. (1101101)2 ( ? )Gray Code
Solution: 1. ( 1 0 1 0 1 1 0 )2
( 1 1 1 1 1 0 1 ) G.C
2. ( 1 1 0 1 1 0 1 )2
( 1 0 1 1 0 1 1 ) G.C
36
Gray To Binary
Down the first binary number and compare each one with the above. If
Same = 0 but Difference=1
Example: Convert the following Gary Codes to binary?
1. (1 1 1 1 1 0 1) Gray Code ( ? )2
2. (1 0 1 1 0 1 1) Gray Code ( ? )2
( 1 0 1 0 1 1 0 )2 ( 1 1 0 1 1 0 1 )2
37
38
ASCII:
39
ASCII Table:
40
ASCII example: 20 PRINT A=“X”;
Symbol or Char. Decimal No. Binary 7bits
2 50 011 0010
0 48 011 0000
Space 32 010 0000
P 80 101 0000
R 82 101 0010
I 73 100 1001
N 78 100 1110
T 84 101 0100
Space 32 010 0000
A 65 100 0001
= 61 011 1101
“ 34 010 0010
X 88 101 1000
“ 34 010 0010
; 59 011 1011
41
Binary Arithmetic:
Binary addition
Binary subtraction
Binary multiplication
Binary division
42
Binary Addition:
The four basic rules for adding binary digits (bits) are as
follows:
◦ 0+0=0 Sum = 0, carry = 0
◦ 0 + 1 = 1 Sum = 1, carry = 0
◦ 1+0=1 Sum = 1, carry = 0
◦ 1 + 1 = 10 Sum = 0, carry = 1
Example:
44
Example:
1101 = 13
1011 = 11 ˟
------------------------------ add
0001101
0011010 + 0100111
0000000
1101000+ 1101000 add
---------------------- ---------------------
10001111 1 0 0 0 1 1 1 1 = 143
45
Binary Subtraction:
The rules for binary subtraction are:
◦ 0 - 0 = 0
◦ 1 - 1 = 0
◦ 1 - 0 = 1
◦ 0 - 1 = 1 with a borrow of 1
46
Ex1: Ex2:
111 1
111001 = 57 11101 = 29
1011 = 11 10011 = 19
--------------------------
------------------------------
101110 = 46 01010 = 10
Ex3: Ex4:
1111 1
10000 = 16 0101 = 5
11 = 3 11 = 3
------------------------------
------------------------------ 0010 = 2
0 1 1 0 1 = 13
Borrow
47
Binary Division:
In the Binary division we have to familiar with
these terms:
1) Divisor (such as 11 & 101 in the last examples)
2) Dividend (such as 111011 & 10000111 in the last
examples)
3) Quotient (such as 10011 & 11011 in the last
examples)
4) Dividend bit (such as 1011 & 0111 in the last
examples)
5) Reminder (such as 10 & 000 in the last examples)
48
Example:
11011 Quotient = 27
49
Example:
10011 Quotient = 19
50
Good luck …
51