Top Banner
ASCII Code 1 Coding Lesson 2 0x002 010
41

Coding

Jan 07, 2016

Download

Documents

Lucas

Coding. Lesson 2 0x002 010. Number Systems. Coding Decimal number system Binary number system Octal number system Hexadecimal number system Conversion. Coding. Computer. Keyboard. Screen. Decoding. Scanner. Coding. Printer. Mouse. Microphone. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Coding

ASCII Code1

Coding

Lesson 2 0x002

010

Page 2: Coding

Number Systems

• Coding • Decimal number system• Binary number system• Octal number system• Hexadecimal number system• Conversion

ASCII Code2

Page 3: Coding

Coding

ASCII Code3

Keyboard

Computer Screen

Printer

Scanner

Mouse

Microphone

Coding Decoding

All Information are converted into codes to be processed by the computer.The codes are numbers in the Binary System (1s & 0s)Why Binary ?

Page 4: Coding

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.

ASCII Code4

Page 5: Coding

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

ASCII Code5

Page 6: Coding

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.

• 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 Code6

Page 7: Coding

Conversion from Binary to Decimal

ASCII Code7

Example: (1101) 2 = 8x1 + 4x1 + 2x0 +1x1 = (13) 10

111 0

• (100)2= 1x22 + 0x21 + 0x 20

=1x4 + 0x2 + 0x1 =4 + 0 +0= (4)10

001

Page 8: Coding

Conversion from Binary to Decimal

• Exercise: What are the decimal values for the following binary numbers:

a- (10010)2 b- (1110111)2 c- (1011011)2

ASCII Code8

(1011)2=1x23 + 0x22 + 1x 21 + 1x 20

=1x 8 + 0x4 + 1 x 2 + 1 x 1 = 8 + 0 +2 +1=(11)10

111 0

Page 9: Coding

Conversion from Binary to Decimal

ASCII Code9

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.

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

Binary Decimal1 111 3111 71111 1511111 31111111 631111111 12711111111 255111111111 5111111111111 102311111111111 2047

Page 10: Coding

Conversion from Binary to Decimalfraction

ASCII Code10

2-1 2-2 2-3 2-4

0.5 0.25 0.125 0.0625

ExamplesConvert binary to decimal: 1) 2)

(110.001)2

(101110.101)2

Sol. Sol.1 1 0 . 0 0 11 0 1 1 1 0 . 1 0 1

4 2 1. . 5. 25. 125 32 16 8 4 2 1. . 5. 25. 125

4 2 1 . .5 .25. 12532 16 8 4 2 1. . 5 .25 .125

=4+ 2. + 125) = 6.125(10 =32 + 8 + 4+ 2. + 5. + 125

=(46.625)10

Page 11: Coding

Decimal to binary conversion

ASCII Code11

Example: 4343 ÷ 2 :Quotient 21, remainder 1: Result > 1

21 ÷ 2 :Quotient 10, remainder 1: Result > 1 110 ÷ 2 :Quotient 5, remainder 0: Result > 0 1 1

5 ÷ 2 :Quotient 2, remainder 1: Result > 1 0 1 12 ÷ 2 :Quotient 1, remainder 0: Result > 0 1 0 1 11 ÷ 2 :Quotient 0, remainder 1: Result > 1 0 1 0 1

1• Exercise: Convert the following decimal numbers to binary22631743000

Page 12: Coding

ASCII Code12

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 : :

Decimal to binary conversion

Page 13: Coding

Fractions conversion from decimal to binary

ASCII Code13

Page 14: Coding

Fractions conversion from decimal to binary

ASCII Code14

Page 15: Coding

Count…

ASCII Code15

Page 16: Coding

Count…

ASCII Code16

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

Page 17: Coding

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 10001Invalid numbers in octal system: 455801 94 8000Numbers are presented in this systems in parentheses with subscript 8 to separate them among other number system e.g. (45612)8

ASCII Code17

Page 18: Coding

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 ASCII Code18

Page 19: Coding

Decimal to octal conversion

• Example 1: (173)10

• Sol. Remainder• 173 8 5• 21 8 5• 2 8 2• The result is ( 25 5)8

ASCII Code19

Page 20: Coding

Example 2: (1583)10

Sol. Remainder 15838

19787248538003

The result is ( 3057)8

Example 2: (1583)10

Sol. Remainder 1583 8

1978 7248 538 00 3

The result is ( 3057)8

ASCII Code20

Page 21: Coding

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 10.84 x 8 = 6.72 60.72 x 8 = 5.76 5

∴ (0.23)10 ≡ (0.165)8

  ASCII Code21

Page 22: Coding

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:

ASCII Code22

Page 23: Coding

ASCII Code23

CONT…

Page 24: Coding

Binary to octal conversion• 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.

•  • Examples: convert from binary to octal.•  • Answer: 111001101 111 001 101•  •  •

7 1 5• ∴(111 001 101)2≡ (715)8

ASCII Code24

Page 25: Coding

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.ASCII Code25

Page 26: Coding

Cont….

Valid numbers in hexadecimal numbers:78A 100 A4BBTo 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:

ASCII Code26

Page 27: Coding

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

ASCII Code27

Page 28: Coding

Converting from decimal to hexadecimal:

ASCII Code28

Page 29: Coding

Converting from hexadecimal to Binary: • because 16=24 then a hexadecimal number

can be converted directly to 4 binary digits ass follows:

29

Page 30: Coding

ASCII Code30

Converting from hexadecimal to Binary:

Page 31: Coding

Converting from Binary to hexadecimal: • we group each 4 numbers to

convert them into one hexadecimal number.

ASCII Code31

Page 32: Coding

ASCII Code32

Decimal(10)

Octal(8)

Binary(2)

Hex(16)

by the Base and take the reminder

By the Weight and take the Sum

Use the table directly

Conversion Diagram

Page 33: Coding

ASCII Code33

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.

Page 34: Coding

ASCII Code34

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.

Page 35: Coding

Ascii Code

ASCII Code35

Page 36: Coding

ASCII Code36

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)

Page 37: Coding

ASCII Code37

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

ASCIIParity 4bit

Page 38: Coding

ASCII Code38

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.

Page 39: Coding

ASCII Code39

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.

Page 40: Coding

ASCII Code40

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.

Page 41: Coding

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:

ASCII Code41