Number Systems And Code Systems
DJM 30073
DIGITAL SYSTEM
Chapter Objectives
Introduction
4
NUMBER SYSTEM
DECIMAL NUMBER
(Base 10)
BINARY NUMBER
(Base 2)
OCTAL NUMBER
(Base 8)
HEXADECIMAL NUMBER
(Base 16)
Number System
DECIMAL NUMBER
number 12 is in base 10.
6
DECIMAL NUMBER SYSTEM
Decimal Numbers
Example:
Express the decimal number 2745.214 as a sum of the values of each digit
BINARY NUMBER
where n is the no of bits used (2n)
9
MSB
(most significant bit)
LSB
(least significant bit)
to show
base 2
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
10 1 0 1 0
11 1 0 1 1
12 1 1 0 0
13 1 1 0 1
14 1 1 1 0
15 1 1 1 1
Decimal Number
Binary Number
BINARY NUMBER SYSTEM
Binary Numbers
Binary Digits
13
23= 8 MSB | 22 = 4 | 21 = 2 | 20 = 1 LSB | Decimal Equivalent |
0 0 0 0 | 0 0 0 0 | 0 0 1 1 | 0 1 0 1 | 0 1 2 3 |
0 0 0 0 | 1 1 1 1 | 0 0 1 1 | 0 1 0 1 | 4 5 6 7 |
1 1 1 1 | 0 0 0 0 | 0 0 1 1 | 0 1 0 1 | 8 9 10 11 |
1 1 1 1 | 1 1 1 1 | 0 0 1 1 | 0 1 0 1 | 12 13 14 15 |
Binary Counting Sequence.
Weights
Convert binary numbers to decimal numbers and vice versa
Binary Decimal
110112 = 1 x 24 + 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 = 2710
1101.012 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20 + 0 x 2-1 + 1 x 2-2 = 13.2510
Example
Convert the binary whole number 1101101 to decimal
Solution:
Weight: 26 25 24 23 22 21 20
Binary : 1 1 0 1 1 0 1
1101101 = 26 + 25 + 23 + 22 + 20
= 64 + 32 + 8 + 4 + 1 = 109
Try This:
1111001
16
Decimal Binary
2 methods : i) reverse process (binary )
ii) repeated division by 2 , 8 , 16
Sum-of-Weight Method
The decimal number 9, for example, can be expressed as the sum of binary weight of:
1 0 0 1
Example:
Convert the following decimal numbers to binary:
a) 12 b) 25 c) 58 d) 82
1100 11001 111010 1010010
18
ii) 2510 = 110012
1 0 1 1 0 12
Reverse Process.
Repeated Division by 2
LSB(least significant bit)
MSB (most significant bit)
Remainder form the binary
25 / 2 = 12.5
0.5 x 2 = 1
19
iii) 0.312510 = 0.01012
LSB
MSB
Stop when fractional part is all zeros
0.312510 x 2 = 0.625
0.625 x 2 = 1.25
0.25 x 2 = 0.50
0.50 x 2 = 1.00
0
1
1
0
0.0 1 0 12
Decimal Number | Binary Number | |||
0 | 0 | 0 | 0 | 0 |
1 | 0 | 0 | 0 | 1 |
2 | 0 | 0 | 1 | 0 |
3 | 0 | 0 | 1 | 1 |
4 | 0 | 1 | 0 | 0 |
5 | 0 | 1 | 0 | 1 |
6 | 0 | 1 | 1 | 0 |
7 | 0 | 1 | 1 | 1 |
8 | 1 | 0 | 0 | 0 |
9 | 1 | 0 | 0 | 1 |
10 | 1 | 0 | 1 | 0 |
11 | 1 | 0 | 1 | 1 |
12 | 1 | 1 | 0 | 0 |
13 | 1 | 1 | 0 | 1 |
14 | 1 | 1 | 1 | 0 |
15 | 1 | 1 | 1 | 1 |
22 21 20
0 0 0
0 0 1
0 2 0
0 2 1
4 0 0
4 0 1
4 2 0
4 2 1
23 22 21 20
8 0 0 0
8 0 0 1
8 0 2 0
8 0 2 1
8 4 0 0
8 4 0 1
8 4 2 0
8 4 2 1
An Application
OCTAL NUMBER
OCTAL NUMBER
subscript 8 shows that number 12 is in base 8.
23
0 1 2 3 4 5 6 7 8 9 10 11 12 13 1415
0 1 2 3 4 5 6 7 10 1112 13 14 15 16 17
Decimal
Octal
to show base 8
conversion of octal to binary numbers and vice versa
24
24
Octal Binary
Convert each octal digit to its 3-bit binary equivalent
4728 = 1001110102
624.58 = 110010100.1012
25
25
Binary Octal
110101102 = 3268
Conversion of octal to decimal numbers and vice versa
26
26
Octal Decimal
3728 = 3 x 82 + 7 x 81 + 2 x 80 = 25010
24.68 = 2 x 81 + 4 x 80 + 6 x 8-1 = 20.7510
Hexadecimal Numbers
HEXADECIMAL NUMBER
29
Value of 10
Hexadecimal
0 1 2 3 4 5 6 7 8 9 10 11 12 13 1415
0 1 2 3 4 5 6 7 8 9 A B C D E F
Decimal
to show base 16
Hexadecimal Numbers
Example:
Conversion of hexadecimal to binary numbers and vice versa
31
35616 = 3 x 162 + 5 x 161 + 6 x 160 = 85410
Hexadecimal Decimal
2AF16 = 2 x 162 + 10 x 161 + 15 x 160 = 68710
Decimal Hexadecimal
32
42310 = 1A716
Remainders form the hexadecimal
204.12510 = CC.216
Hexadecimal Numbers
Hexadecimal Numbers
Hexadecimal Numbers
Hexadecimal Numbers
ARITHMETIC OPERATION
a) Addition
A 11101100
B + 1100110
101010010
b) Subtraction
A 101
B - 011
010
38
Right Column:
1 – 1 = 0
Middle Column:
Borrow 1 from next column to the left, making a 10 in this column, then 10-1=1
Left Column:
When a 1 is borrowed, a 0 is left, so 0-0=0
1’s and 2’s Complements of Binary Numbers
Finding the 1’s Complement
The 1’s complement of a binary number is found by changing all 1s to 0s and all 0s to 1s.
Example:
1 0 1 1 0 0 1 0 (Binary Number)
0 1 0 0 1 1 0 1 (1’s Complement)
NOT Gate
Finding the 2’s Complement
The 2’s complement of a binary number is found by adding 1 to the LSB of the 1’s complement
Find the 2’s complement of 10110010
10110010 (Binary number)
+ 01001101 (1’s complement)
1 (Add 1)
01001110
� COMPLEMENT OF BINARY NUMBERS
or
leave all LSB ‘0’s and the first ‘1’ unchanged and replaced 1’s with 0’s and the 0’s with 1’s in all
42
ARITHMETIC OPERATIONS USING NUMBER SYSTEMS
ADDITION
SUBTRACTION
Example: Perform each the following subtractions of the sign numbers
(a) 00001000 – 00000011 (b) 00001100 – 11110111
(c) 11100111 - 00010011 (d) 10001000 – 11100010
Solution:
(a) 8 – 3 = 8 + (-3) = 5 00001000 minuend (+8)
+ 11111101 2’s of subtrahend (-3)
100000101 Difference (+5)
44
Discard Carry
(b) 12-(-9) = 12+9=21
00001100 minuend (+12)
+ 00001001 2’s of subtrahend (+9)
00010101 Difference (+21)
(c) -25-(+19) = -25+(-9)=-44
11100111 minuend (-25)
+ 11101101 2’s of subtrahend (-19)
111010100 Difference (-44)
(d) -120-(-30) = -120+30=-90
10001000 minuend (-120)
+ 00011110 2’s of subtrahend (+30)
10100110 Difference (-90)
Exercise : Subtract 01000111 from 01011000
45
Discard Carry
convert BCD 8421 codes to binary number and vise versa
Example: convert each decimal numbers to BCD
(a) 35 (b) 98 (c) 170 (d) 2469
Solution:
(a) 3 5 ( decimal )
0011 0101 ( BCD)
(b) 9 8
1001 1000
46
Example: convert each BCD to decimal numbers
(a) 10000110 (b) 00110101000
(c) 1001010001110000
Solution:
(a) 1000 0110
8 6
(b) 0001 1010 1000 1 10 8
* BCD code does not use (10 is invalid codes)
(c) 1001 0100 0111 0000
9 4 7 0
47
BCD
BCD
8 7 4
0100 0111 0100 = 010001110100BCD
BCD
BCD 8421 CODES
Decimal | 5421 | 5311 | 4221 | 3321 | 2421 | 8421 | 7421 |
0 | 0000 | 0000 | 0000 | 0000 | 0000 | 0000 | 0000 |
1 | 0001 | 0001 | 0001 | 0001 | 0001 | 0001 | 0001 |
2 | 0010 | 0011 | 0010 | 0010 | 0010 | 0010 | 0010 |
3 | 0011 | 0100 | 0011 | 0011 | 0011 | 0011 | 0011 |
4 | 0100 | 0101 | 1000 | 0101 | 0100 | 0100 | 0100 |
5 | 1000 | 1000 | 0111 | 1010 | 1011 | 0101 | 0101 |
6 | 1001 | 1001 | 1100 | 1100 | 1100 | 0110 | 0110 |
7 | 1010 | 1011 | 1101 | 1101 | 1101 | 0111 | 1000 |
8 | 1011 | 1100 | 1110 | 1110 | 1110 | 1000 | 1001 |
9 | 1100 | 1101 | 1111 | 1111 | 1111 | 1001 | 1010 |
Alphanumeric Codes
NUMBER CODES ACSII
53
ASCII CODE TABLE
MSB LSB |
Binary |
000 |
001 |
010 |
011 |
100 |
101 |
110 |
111 |
Binary |
Hex |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
0000 | 0 | Nul | Del | sp | 0 | @ | P |
| p |
0001 | 1 | Soh | Dc1 | 1 | 1 | A | Q | a | q |
0010 | 2 | Stx | Dc2 | “ | 2 | B | R | b | r |
0011 | 3 | Etx | Dc3 | # | 3 | C | S | c | s |
0100 | 4 | Eot | Dc4 | $ | 4 | D | T | d | t |
0101 | 5 | End | Nak | % | 5 | E | U | e | u |
0110 | 6 | Ack | Syn | & | 6 | F | V | f | v |
0111 | 7 | Bel | Etb | ‘ | 7 | G | W | g | w |
1000 | 8 | Bs | Can | ( | 8 | H | X | h | x |
1001 | 9 | HT | Em | ) | 9 | I | Y | i | y |
1010 | A | LF | Sub | . | : | J | Z | j | z |
1011 | B | VT | Esc | + | ; | K |
| k |
|
1100 | C | FF | FS | , | < | L |
| l |
|
1101 | D | CR | GS | - | = | M |
| m |
|
1110 | E | SO | RS | . | > | N |
| n |
|
1111 | F | SI | US | / | ? | O |
| o |
|
Example:
The following is a message encoded in ASCII code.
What is the message?
1001000 1000101 1001100 1010000
Solution:
H E L P
TRY THIS
a) 54 4F 4C 4F 4E 47
b) 48 45 4C 4C 4F
c) 41 50 41 4B 48 41 42 41 52
d) GO TO 25
Thank You
“ Buku yang selalu dibaca tidak akan mengumpul habuk dan debu. Berjinaklah dengan buku kerana ia adalah teman yang paling berguna menimba ilmu “