D ATA REPRESENTATION, BINARY SYSTEM, B IT, B YTE, ASCII C ODE Chapter 4 Lecturer In Charge: Manesh T...

Post on 05-Jan-2016

215 views 2 download

transcript

DATA REPRESENTATION, BINARY SYSTEM, BIT, BYTE, ASCII CODEChapter 4

Lecturer In Charge: Manesh T

1

DATA REPRESENTATION

• Data Representation refers to how Computers store lots of different types of information:

• numbers • text • graphics of many varieties (stills, video,

animation) • sound

2

MEMORY STRUCTURE IN COMPUTER• Memory consists of bits (0 or 1)

– a single bit can represent two pieces of information

• bytes (=8 bits) – a single byte can represent 256 =

2x2x2x2x2x2x2x2 = 28 pieces of information • words (=2,4, or 8 bytes)

– a 2 byte word can represent 2562 pieces of information (approximately 65 thousand).

• Byte addressable - each byte has its own address.

3

BINARY SYSTEM

4

CLASSIFICATIONS

5

STORAGE UNITS

6

NUMBER SYSTEMS

Binary (2) Decimal (10) Octal (8)Hexadecimal

(16)0000' 0 0 0000'0001' 1 1 0001'0010' 2 2 0010'0011' 3 3 0011'0100' 4 4 0100'0101' 5 5 0101'0110' 6 6' 0110'0111' 7 7 0111'1000' 8   1000'1001' 9   1001'1010' 10   A1011' 11   B1100' 12   C1101' 13   D1110' 14   E1111' 15   F

7

CONVERSION AMONG BASES

The possibilities:

Hexadecimal

Decimal Octal

Binary

pp. 40-468

QUICK EXAMPLE

2510 = 110012 = 318 = 1916

Base

9

DECIMAL TO DECIMAL (JUST FOR FUN)

Hexadecimal

Decimal Octal

Binary

Next slide…10

12510 => 5 x 100 = 52 x 101 = 201 x 102 = 100

125

Base

Weight

11

BINARY TO DECIMAL

Hexadecimal

Decimal Octal

Binary

12

BINARY TO DECIMAL

Technique Multiply each bit by 2n, where n is the “weight”

of the bit The weight is the position of the bit, starting

from 0 on the right Add the results

13

EXAMPLE

1010112 => 1 x 20 = 11 x 21 = 20 x 22 = 01 x 23 = 80 x 24 = 01 x 25 = 32

4310

Bit “0”

14

OCTAL TO DECIMAL

Hexadecimal

Decimal Octal

Binary

15

OCTAL TO DECIMAL

Technique Multiply each bit by 8n, where n is the “weight”

of the bit The weight is the position of the bit, starting

from 0 on the right Add the results

16

EXAMPLE

7248 => 4 x 80 = 42 x 81 = 167 x 82 = 448

46810

17

HEXADECIMAL TO DECIMAL

Hexadecimal

Decimal Octal

Binary

18

HEXADECIMAL TO DECIMAL

Technique Multiply each bit by 16n, where n is the “weight”

of the bit The weight is the position of the bit, starting

from 0 on the right Add the results

19

EXAMPLE

ABC16 => C x 160 = 12 x 1 = 12 B x 161 = 11 x 16 = 176 A x 162 = 10 x 256 = 2560

274810

20

DECIMAL TO BINARY

Hexadecimal

Decimal Octal

Binary

21

DECIMAL TO BINARY

Technique Divide by two, keep track of the remainder First remainder is bit 0 (LSB, least-significant bit) Second remainder is bit 1 Etc.

22

EXAMPLE12510 = ?2

2 125 62 12 31 02 15 12 7 12 3 12 1 12 0 1

12510 = 11111012

23

OCTAL TO BINARY

Hexadecimal

Decimal Octal

Binary

24

OCTAL TO BINARY

Technique Convert each octal digit to a 3-bit equivalent

binary representation

25

EXAMPLE7058 = ?2

7 0 5

111 000 101

7058 = 1110001012

26

HEXADECIMAL TO BINARY

Hexadecimal

Decimal Octal

Binary

27

HEXADECIMAL TO BINARY

Technique Convert each hexadecimal digit to a 4-bit

equivalent binary representation

28

EXAMPLE10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112

29

CLASS WORK

Convert Decimal to Binary1. (421) 10 = ( ) 2

2. (1025)10 = ( ) 2

3. (368)10 = ( ) 2

4. (687)10 = ( ) 2

5. (625)10 = ( ) 2

6. (752)10 = ( ) 2

30

CLASS WORK

Convert Binary to Hexadecimal1. (10110101001011100010)2 = ( )16

2. (10000100110110000101)2 = ( )16

3. (11100010101010011010)2 = ( )16

4. (10111100011011101101)2 = ( )16

5. (0101000110110101010)2 = ( )16

6. (101111111010011010)2 = ( )16

31

CLASS WORK

Convert Hexadecimal to Binary1. (AF1) 16 = ( ) 2

2. (924)16 = ( ) 2

3. (3569)16 = ( ) 2

4. (4526)16 = ( ) 2

5. (6548)16 = ( ) 2

6. (1334)16 = ( ) 2

32

ASCII

The most common code used in computers is ASCII (American Standard Code for Information Interchange).

ASCII provides codes for letters, digits, punctuation marks, and other special characters.

The ASCII code for A is 65 = 01000001

33

ASCII CODESSp ! “ # $ % & ‘ ( ) * + , -

32 33 34 35 36 37 38 39 40 41 42 43 44 45

. / 0 1 2 3 4 5 6 7 8 9 : ;

46 47 48 49 50 51 52 53 54 55 56 57 58 59

< = > ? @ A B C D E F G H I

60 61 62 63 64 65 66 67 68 69 70 71 72 73

J K L M N O P Q R S T U V W

74 75 76 77 78 79 80 81 82 83 84 85 86 87

X Y Z [ \ ] ^ _ ` a b c d e

88 89 90 91 92 93 94 95 96 97 98 99 100 101

f g h i j k l m n o p q r s

102 103 104 105 106 107 108 109 110 111 112 113 114 115

t u v w x y z { | } ~

116 117 118 119 120 121 121 123 124 125 12634

ASCII REPRESENTATION OF TEXT

Since the ASCII codes for ART are

65, 82, and 84, the three bytes representing the word ART would be 01000001 0101010 01010100

• Nearly all software which deals with text (Notepad, WordPerfect, Word) use the ASCII codes to represent such text, though they may use proprietary codes to deal with fonts, etc.

35

CHAPTER 4 END

36