Personal Computer

Download Report

Transcript Personal Computer

Coding
1
ASCII Code
Number Systems
•
•
•
•
•
•
2
Coding
Decimal number system
Binary number system
Octal number system
Hexadecimal number system
Conversion
ASCII Code
Coding
Keyboard
Screen
Computer
Scanner
Mouse
Coding
Decoding
Printer
Microphone
All Information are converted into codes to be processed by the computer.
The codes are numbers in the Binary System (1s & 0s)
Why Binary ?
3
ASCII Code
Decimal Number System
• This is the used number system in our
life calculations.
• It contains 10 symbols to represent the
numbers which are
{0,1,2,3,4,5,6,7,8,9}, any number in the
system can be represented in away that
it depends on the power of 10.
4
ASCII Code
Decimal (base 10)
Examples:
2434=2000+400+30+4
=2x1000 + 4x100 + 3x10 + 4x1
=2x103 + 4x102 +3x101 + 4x100
Example 2:
1479 = 1 * 103 + 4 * 102 + 7 * 101 + 9 * 100
5
ASCII Code
Binary Number system
• This number system contains only two
symbols to represent its numbers,
which are {0 and 1} only.
• e.g.: 100, 101 1000001010 are accepted numbers in the binary
system where 10020 is not accepted because it contains the
symbol (2) which is not included in the set of symbols.
•
6
In order to distinguish the numbers in the binary system from the
decimal system, they are put in parenthesis and the number 2 is put
to the bottom right of the brackets as a subscript; like (1001)2 for the
binary system , and the number 10 is put to for the decimal system ;
like (1001)10.
ASCII Code
Conversion from Binary to Decimal
1
1
0
1
Example: (1101) 2 = 8x1 + 4x1 + 2x0 +1x1 = (13) 10
1
•
7
(100)2= 1x22 + 0x21 + 0x 20
=1x4 + 0x2 + 0x1
=4 + 0 +0= (4)10
0
0
ASCII Code
Conversion from Binary to Decimal
1
0
1
1
(1011)2=1x23 + 0x22 + 1x 21 + 1x 20
=1x 8 + 0x4 + 1 x 2 + 1 x 1
= 8 + 0 +2 +1=(11)10
• Exercise: What are the decimal values for the following binary
numbers:
a- (10010)2
8
b- (1110111)2
c- (1011011)2
ASCII Code
Conversion from Binary to Decimal
Rule: If the binary number consists of only ones, you can find its
decimal equivalent number using this formula: Decimal = 2n – 1
Where n is the number of bits, for example 1111 has 4 bits.
Example 1:
(11111111)2 has 8 bits, so
Decimal = 28 – 1 = 255
Example 2:
(111111111)2 has 9 bits, so
Decimal = 29 – 1 = 511
9
Binary
1
11
111
1111
11111
111111
1111111
11111111
111111111
1111111111
11111111111
Decimal
1
3
7
15
31
63
127
255
511
1023
2024
ASCII Code
Conversion from Binary to Decimal
fraction
2-1
2-2
2-3
2-4
0.5
0.25
0.125
0.0625
Examples
Convert binary to decimal:
1)
2)
(110.001)2
(101110.101)2
Sol.
1
0
1 1 1 0 . 1
Sol.
0
1
0
1
32 16 8 4 2 1 . .5 .25 .125
4 2 1 . .5 .25 .125
32 16 8 4 2 1 . .5 .25 .125
4 2 1 . .5 .25 .125
=32 + 8 + 4 +2 + .5 + .125
=(46.625)10
10
11 0 . 0
= 4 +2 + .125 = (6.125)10
ASCII Code
Decimal to binary conversion
Example: 43
43 ÷ 2: Quotient 21, remainder 1: Result > 1
21 ÷ 2: Quotient 10, remainder 1: Result > 1 1
10 ÷ 2: Quotient 5, remainder 0: Result > 0 1 1
5 ÷ 2: Quotient 2, remainder 1: Result > 1 0 1 1
2 ÷ 2: Quotient 1, remainder 0: Result > 0 1 0 1 1
1 ÷ 2: Quotient 0, remainder 1: Result > 1 0 1 0 1 1
11
• Exercise: Convert the following decimal numbers to binary
22
63
174
3000
ASCII Code
Decimal to binary conversion
12
Decimal
Binary
Decimal
Binary
Decimal
Binary
0
0
8
1000
16
10000
1
1
9
1001
17
10001
2
10
10
1010
18
10010
3
11
11
1011
19
10011
4
100
12
1100
20
10100
5
101
13
1101
21
10101
6
110
14
1110
22
10110
7
111
15
1111
:
:
ASCII Code
Fractions conversion from decimal
to binary
13
ASCII Code
Fractions conversion from decimal
to binary
14
ASCII Code
Count…
15
ASCII Code
Count…
Exercise: convert the following decimal numbers to
binary:
a- (85)
b- (117)
c- (43.75) d- (0.15625) e- (36.045)
2- Arrange the following binary numbers in ascending
order
a- 1101
b- 1110
c- 1011.11
d- 1101.001
16
ASCII Code
Octal Number system
This system contains 8 digits (symbols) which are the
first 8 decimal digits (0,1,2,3,4,5,6,7); (there are no
8 & 9 in the octal number system).
Valid numbers in octal system: 45612
70125 20
10001
Invalid numbers in octal system: 455801 94 8000
Numbers are presented in this systems in parentheses
with subscript 8 to separate them among other
number system e.g. (45612)8
17
ASCII Code
Octal Number (base 8)
• Example: convert (3057)8 to decimal.
• Sol.
3057=3x83+0x82+5x81+7x80
•
=3x512+0x64+5x8+7x1
•
=1536+0+40+7
•
=1583
• then (3057)8 is equivalent to (1583)10
18
ASCII Code
Decimal to octal conversion
• Example 1: (173)8
• Sol.
Remainder
•
173 8
5
•
21 8
5
•
2
8
2
• The result is ( 25 5)8
19
ASCII Code
Example 2:
Remainder
Example 2: (1583)
10
8
Sol.
Remainder
7 8
1583 8
5 8
1978 7
0 8
248
5
3
38
0
The
result
is
0
3
(1583)10
Sol.
1583
197
24
3
0
( 3057)8
The result is ( 3057)8
20
ASCII Code
Converting decimal fractions to
octal
This can be obtained by multiply the
decimal fraction by 8 and watch the
carry into integer’s position.
Example: (0.23)10
0.23 x 8 =1.84
1
0.84 x 8 = 6.72
6
0.72 x 8 = 5.76
5
∴ (0.23)10 ≡ (0.165)8
21
ASCII Code
Octal to binary conversion
Because 8 = 23 , we can convert from
octal to binary directly, that is each digit
in octal will match 3 digits in binary as
follows:
22
ASCII Code
CONT…
23
ASCII Code
Binary to octal conversion
•
24
Binary to octal conversion: this conversion can be obtained as an opposite
to the conversion from octal to binary that is grouping the binary number into
threes, and converting them to octal ones.
•
•
•
•
•
•
•
Answer: 111001101
•
∴(111 001 101)2≡ (715)8
Examples: convert from binary to octal.
111
001 101
7
1
5
ASCII Code
Hexadecimal Number system
This system contains sixteen symbols to
represent its numbers, Which are:
{0,1, 2, 3 ,4,5,6,7,8,9,A,B,C,D,E,F}
Where
A represent the value (10)10,
B represent (11)10,
C represent (12)10,
D represent (13)10,
E represent (14)10,
F represent (15)10.
25
ASCII Code
Cont….
Valid numbers in hexadecimal numbers:
78A 100
A4BB
To distinguish hexadecimal number from other systems,
we put the hexadecimal numbers between two
parenthesis like (49B3)16.
The weights of the numbers in hexadecimal number
system are evaluated according to the positional
number system:
26
ASCII Code
Converting from hexadecimal to decimal:
Examples:
(34)16
Solution: 3x161 + 4x160
=3x16 + 4x1
=48+4 =(52)10
(34)16  (52)10
(40AC)16
Solution: 4 x 163 + 0 x 162 + Ax161 + Cx160
=4 x 4096 + 0 x 265 + 10 x 16 + 12 x 1
=16384 + 0 + 160 + 12
=(16556)10 (40AC)16  (16556)10
27
ASCII Code
Converting from decimal to hexadecimal:
28
ASCII Code
Converting from hexadecimal to Binary:
• because 16=24 then a hexadecimal number can be
converted directly to 4 binary digits ass follows:
29
Converting from hexadecimal to Binary:
30
ASCII Code
Converting from Binary to hexadecimal:
• we group each 4 numbers to convert
them into one hexadecimal number.
31
ASCII Code
Conversion Diagram
by the Base and
take the reminder
Decimal(10)
Binary(2)
By the Weight
and take the Sum
32
Octal(8)
Use the table
directly
Hex(16)
ASCII Code
ASCII Code
ASCII stands for American Standard Code for
Information Interchange.
The ASCII is a 7 bits code whose format is
X6X5X4X3X2X1X0, where each X is 0 or 1.
The ASCII code is used to represent the
English language characters (letters,
numbers, symbols and punctuations) by
binary numbers to used in computers.
33
ASCII Code
Cont.... ASCII Code
Notes:
In computer processing the “space” is a
significant character, where the ASCII code of the
space is 0100000 .
Upper case and lower case letters have different
values in ASCII code.
For example the ASCII code for A is 1000001 and
the ASCII code for a is 1100001.
34
ASCII Code
Ascii Code
35
ASCII Code
Example:
Write
Print S in ASCII code.
P(101 0000) r(111 0010) i(110 1001)
n(110 1110) t(111 0100) space(010
0000) S(101 0011)
36
ASCII Code
Parity Bit
Note: Read page number 122 from the book.
The parity bit is an additional bit
added to the ASCII code to catch errors
in transmitting data.
So, the message format for each
character (ASCII code with parity bit) is
X7X6X5X4X3X2X1X0
Parityِ bit
37
ASCII
ASCII Code
 Types of Parity Bit:
1. Odd Parity Bit: in this type number
of ones in the message for each
character (ASCII code and parity bit)
must be odd.
2. Even Parity Bit: in this type number
of ones in the message for each
character (ASCII code and parity bit)
must be even.
38
ASCII Code
Suppose that two devices are
communicating with even parity.
The transmitting device (Sender)
sends data, it counts the number of
ones in each group of seven bits. If
number of ones is even, it sets the
parity bit to 0; if the number of ones is
odd, it sets the parity bit to 1.
In this way, every message has an even
number of ones.
39
ASCII Code
Cont... Parity Bit
On the receiving side, the device
checks each message to make sure that
it has an even number of ones.
If the receiving device finds an odd
number of ones, the receiver knows
there was an error during transmission.
40
ASCII Code
Binary Coded Decimal(BCD):
• a format for representing decimal numbers (integers) in which
each digit is represented by four bits . For example, the number
375 would be represented as:
41
ASCII Code