Top Banner
1 COMPUTER ORGANIZATION AND ARCHITECTURE Chapter 2:Number System and Data Representation
36

Number System and Data Representation

Oct 27, 2014

Download

Documents

wasif28
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: Number System and Data Representation

1

COMPUTER ORGANIZATION ANDARCHITECTURE

Chapter 2:Number System and Data Representation

Page 2: Number System and Data Representation

2

Chapter II Number System and Data Representation

1. Number System2. Data Representation3. Integer

Representation

Page 3: Number System and Data Representation

3

Fundamental to understand how computers work is understanding the number system that computer use to store data and communicate with each other.

Number system been used to understand computer:

Base 10 (decimal) E.g.: 394510 / 3945d

Base 2 (binary) E.g.: 101010112 / 10101011b

Base 16 (hexadecimal) E.g.: 0A3E16 / 0A3Eh

1. Number Systems

Page 4: Number System and Data Representation

4

Number Systems (cont.)The Decimal SystemThe Decimal System In everyday life we use a system based on decimal digits.

Consider the number 4728 means four thousands, seven hundreds, two tens, plus eight:

4728 = (4 x 1000) + (7 x 100) + (2x10) + 8

The decimal system is said to have a base or radix of 10. Each digit in the number is multiplied by 10 raised to a power corresponding to that digit’s position:

4728 = (4 x 103) + (7 x 102) + (2 x 101) + (8 x 100)

Page 5: Number System and Data Representation

5

The Binary SystemThe Binary System

Number Systems (cont.)

In the binary system, we have only two digits, 1 and 0. Thus, number in the binary system are represented to the base 2.

Each digits in a binary number also have a value depending on its position:

1002 = (1 x 22 ) + (0 x 21 ) + (0 x20 ) = 410

101011b = (1 x 25) + (0 x 24) + (1 x 23) + (0 x 22) + (1 x 21) +

(1 x 20) = 43d

Page 6: Number System and Data Representation

6

Number Systems (cont.)

The The Hexadecimal System System

A computer’s world is a binary world and communication of instruction and data by the devices that process them is always in binary.

Binary system is very difficult for human being. Human being are comfortable to decimal number system.

However calculations to convert binary to decimal are relatively complex.

A notation known as hexadecimal has been adopted. Binary digits are grouped into sets of four. Each possible combination of four binary digits is given a symbol (hexadecimal digits) as follows:

Page 7: Number System and Data Representation

7

Number Systems (cont.)

The The Hexadecimal System (cont.) System (cont.)

0000 = 0

0001 = 1

0010 = 2

0011 = 3

0100 = 4

0101 = 5

0110 = 6

0111 = 7

1000 = 8

1001 = 9

1010 = A

1011 = B

1100 = C

1101 = D

1110 = E

1111 = F

Page 8: Number System and Data Representation

8

Number Systems (cont.)The The Hexadecimal System (cont.) System (cont.)

In the hexadecimal system, we have 16 hexadecimal digits. Thus, number in the hexadecimal system are represented to the base 16.

Each digits in a hexadecimal number also have a value depending on its position:

2C16= (2 x 161)+ (C x 160)

= (2 x 161)+ (12 x 160) = 4410

The reason for using hexadecimal notation are because it is more compact than binary notation and it is extremely easy to convert between binary and hexadecimal.

Page 9: Number System and Data Representation

9

Number Systems (cont.)Decimal Binary Hexadecimal

0 0000 0

1 0001 1

2 0010 2

3 0011 3

4 0100 4

5 0101 5

6 0110 6

7 0111 7

8 1000 8

9 1001 9

10 1010 A

11 1011 B

12 1100 C

13 1101 D

14 1110 E

15 1111 F

Page 10: Number System and Data Representation

10

Conversion Between Number Systems

Converting Binary to Decimal Converting Hex to Decimal

Converting Decimal to Binary Converting Decimal to Hex

Converting Between Hex and Binary

Number Systems (cont.)

Page 11: Number System and Data Representation

11

Converting Binary to Decimal

101001b to decimal

101001b = (1 x 25) + (0 x 24) + (1 x 23) + (0 x 22) + (0 x 21) + (1 x 20)

= 32 + 0 + 8 + 0 + 0 + 1 = 41d

Number Systems (cont.)

Page 12: Number System and Data Representation

12

Number Systems (cont.)

Converting Hex to Decimal

A3F16 to decimal

A3F16 = (A x 162) + (3 x 161) + (F x 160 )

= (10 x 256) + (3 x 16) + (15 x 1)

= 262310

Page 13: Number System and Data Representation

13

Converting Decimal to Binary Decimal can be converted in to a binary

systems with the Remainder Method Example: Convert 26d to base 2

=> 26d = 11010b

26/2 = 13 0

13/2 = 6 1

6/2 = 3 0

3/2 = 1 1

1/2 = 0 1 Most significant bit

Least significant bit

Number Systems (cont.)

Page 14: Number System and Data Representation

14

How about floating point number? E.g.: Convert 0.875d into base 2 number.

=> 0.875d = 0.1110b

0.875 x 2 = 1.75 1

0.75 x 2 = 1.5 1

0.5 x 2 = 1.0 1

0 x 2 = 0 0

Converting Decimal to Binary (Floating point number)

Number Systems (cont.)

Page 15: Number System and Data Representation

15

Converting Decimal to Hex

Decimal can be converted into a hex with the Remainder Method

Example: Convert 425d to base 16425 / 16 = 26 9 -> 9 26 / 16 = 1 10 -> A 1 / 16 = 0 1 -> 1

=> 425d = 1A9h

Number Systems (cont.)

Page 16: Number System and Data Representation

16

Converting Between Hex and Binary To convert a hex number to binary, we

need only express each hex digit in binary E.g.: Convert DE116 to binary D E 1

= 1101 1110 0001 = 110111100001b

To go from binary to hex, just reverse this process100100012 = 1001 0001 = 9116

Number Systems (cont.)

Page 17: Number System and Data Representation

17

1. Number System2. Data

Representation3. Integer

Representation

Page 18: Number System and Data Representation

18

A common form of data are letters of the alphabet (A to Z), numerals (0 to 9), some symbols (@, &, *) and certain control character (Ctrl,Shift).

This types of data is convenient for human being but all of the data in digital computer represented in binary form.

Some coding systems are used to represent these data into the binary form. (Characters are represented by a sequence of bits.)

2. Data Representation

Page 19: Number System and Data Representation

19

The famous coding system been used for data representation are:ASCII (American Standard Code for

Information Interchange)EBCDIC (Extended Binary Coded

Decimal Interchange Code )BCD (Binary Coded Decimal)

Data Representation (cont.)

Page 20: Number System and Data Representation

20

ASCII ASCII is used in almost all present-day personal

computers. Each alphabetic, numeric, or special character is

represented with a 7-bit binary number (a string of seven 0s or 1s).

128 possible characters can be represented.27

The eight bit may be set to 0 or used as a parity bit for error checking on communication lines or other device-specific functions.

Example: char A=65 in decimal,41 in hex, 0100 0001 in binary.

Data Representation (cont.)

Page 21: Number System and Data Representation

21

PrintableRepresentation

0000 0000 0 0 NUL ␀ Null character0000 0001 1 1 SOH ␁ Start of Header0000 0010 2 2 STX ␂ Start of Text0000 0011 3 3 ETX ␃ End of Text

0000 0100 4 4 EOT ␄End of Transmission

0000 0101 5 5 ENQ ␅ Enquiry

0000 0110 6 6 ACK ␆Acknowledgment

0000 0111 7 7 BEL ␇ Bell0000 1000 8 8 BS ␈ Backspace0000 1001 9 9 HT ␉ Horizontal Tab0000 1010 10 0A LF ␊ Line Feed0000 1011 11 0B VT ␋ Vertical Tab0000 1100 12 0C FF ␌ Form Feed

0000 1101 13 0D CR ␍ Carriage return0000 1110 14 0E SO ␎ Shift Out0000 1111 15 0F SI ␏ Shift In

0001 0000 16 10 DLE ␐Data Link Escape

0001 0001 17 11 DC1 ␑XON Device Control 1

0001 0010 18 12 DC2 ␒Device Control 2

0001 0011 19 13 DC3 ␓XOFF Device Control 3

0001 0100 20 14 DC4 ␔Device Control 4

0001 0101 21 15 NAK ␕

Negative Acknowledgement

0001 0110 22 16 SYN ␖Synchronous Idle

0001 0111 23 17 ETB ␗End of Trans. Block

0001 1000 24 18 CAN ␘ Cancel0001 1001 25 19 EM ␙ End of Medium0001 1010 26 1A SUB ␚ Substitute0001 1011 27 1B ESC ␛ Escape0001 1100 28 1C FS ␜ File Separator

0001 1101 29 1D GS ␝Group Separator

0001 1110 30 1E RS ␞Record Separator

0001 1111 31 1F US ␟ Unit Separator0111 1111 127 7F DEL ␡ Delete

Binary Decimal Hex Abbreviation Name/Meaning

Data Representation (cont.)

ASCII Control Characters

The first thirty-two codes (numbers 0-31 decimal) in ASCII are reserved for control characters: codes that may not themselves represent information, but that are used to control devices (such as printers) that make use of ASCII. For example, character 10 represents the "line feed" function (which causes a printer to advance its paper), and character 27 represents the "escape" key found on the top left of common keyboards.

The first thirty-two codes (numbers 0-31 decimal) in ASCII are reserved for control characters: codes that may not themselves represent information, but that are used to control devices (such as printers) that make use of ASCII. For example, character 10 represents the "line feed" function (which causes a printer to advance its paper), and character 27 represents the "escape" key found on the top left of common keyboards.

Page 22: Number System and Data Representation

22

Code 32 is the "space" character, denoting the space between words, which is produced by the large space bar of a keyboard.

Code 32 is the "space" character, denoting the space between words, which is produced by the large space bar of a keyboard.

ASCII Printable Characters

Codes 33 to 126 are called the printable characters, which represent letters, digits, punctuation marks, and a few miscellaneous symbols.

Codes 33 to 126 are called the printable characters, which represent letters, digits, punctuation marks, and a few miscellaneous symbols.

Data Representation (cont.)

Page 23: Number System and Data Representation

23

Binary Decimal Hex Graphic

0010 0000 32 20 (blank) (␠ )

0010 0001 33 21 !

0010 0010 34 22 "

0010 0011 35 23 #

0010 0100 36 24 $

0010 0101 37 25 %

0010 0110 38 26 &

0010 0111 39 27 '

0010 1000 40 28 (

0010 1001 41 29 )

0010 1010 42 2A *

0010 1011 43 2B +

0010 1100 44 2C ,

0010 1101 45 2D -

0010 1110 46 2E .

0010 1111 47 2F /

0011 0000 48 30 0

0011 0001 49 31 1

0011 0010 50 32 2

0011 0011 51 33 3

0011 0100 52 34 4

0011 0101 53 35 5

0011 0110 54 36 6

0011 0111 55 37 7

0011 1000 56 38 8

0011 1001 57 39 9

0011 1010 58 3A :

0011 1011 59 3B ;

0011 1100 60 3C <

0011 1101 61 3D =

0011 1110 62 3E >0011 1111 63 3F ?

Data Representation (cont.)ASCII Printable Characters

Page 24: Number System and Data Representation

24

Binary Decimal Hex Graphic

0100 0000 64 40 @

0100 0001 65 41 A

0100 0010 66 42 B

0100 0011 67 43 C

0100 0100 68 44 D

0100 0101 69 45 E

0100 0110 70 46 F

0100 0111 71 47 G

0100 1000 72 48 H

0100 1001 73 49 I

0100 1010 74 4A J

0100 1011 75 4B K

0100 1100 76 4C L

0100 1101 77 4D M

0100 1110 78 4E N

0100 1111 79 4F O

0101 0000 80 50 P

0101 0001 81 51 Q

0101 0010 82 52 R

0101 0011 83 53 S

0101 0100 84 54 T

0101 0101 85 55 U

0101 0110 86 56 V

0101 0111 87 57 W

0101 1000 88 58 X

0101 1001 89 59 Y

0101 1010 90 5A Z

0101 1011 91 5B [

0101 1100 92 5C \

0101 1101 93 5D ]

0101 1110 94 5E ^0101 1111 95 5F _

Data Representation (cont.)ASCII Printable Characters (cont.)

Page 25: Number System and Data Representation

25

Binary Decimal Hex Graphic0110 0000 96 60 `0110 0001 97 61 a0110 0010 98 62 b0110 0011 99 63 c0110 0100 100 64 d0110 0101 101 65 e0110 0110 102 66 f0110 0111 103 67 g0110 1000 104 68 h0110 1001 105 69 i0110 1010 106 6A j0110 1011 107 6B k0110 1100 108 6C l0110 1101 109 6D m0110 1110 110 6E n

0110 1111 111 6F o0111 0000 112 70 p0111 0001 113 71 q0111 0010 114 72 r0111 0011 115 73 s0111 0100 116 74 t0111 0101 117 75 u0111 0110 118 76 v0111 0111 119 77 w0111 1000 120 78 x0111 1001 121 79 y0111 1010 122 7A z0111 1011 123 7B {0111 1100 124 7C |0111 1101 125 7D }0111 1110 126 7E ~

Data Representation (cont.)ASCII Printable Characters (cont.)

Page 26: Number System and Data Representation

26

EBCDIC EBCDIC (pronounced either "ehb-suh-dik" or "ehb-kuh-dik")

is a binary code for alphabetic and numeric characters that IBM developed for its larger operating systems

Each alphabetic or numeric character is represented with an 8-bit binary number (a string of eight 0's or 1's).

256 possible characters (letters of the alphabet, numerals, and special characters) are defined.

EBCDIC uses more or less the same characters as ASCII, but different code points. Example: A= C1 in hex, 1100 0011 in binary.

Today outside IBM everyone uses ASCII instead; EBCDIC is considered a bit of a dinosaur.

Data Representation (cont.)

Page 27: Number System and Data Representation

27

Data Representation (cont.)

BCDIn BCD, 4 bit binary number were used to

represent 1 decimal number ( e.g 3d=0011b, 9d=1001b)

Highest decimal number were coded to BCD is 9 (1001). Thus, 1010, 1011, 1110 and 1111 were not used.

To encode the number such as 43; use:

43d= 0100 0011b

The BCD format usually used in the BIOS at Personal Computer (PC) to keeps the date and time for historical reason.

Page 28: Number System and Data Representation

28

1. Number System2. Data Representation3. Integer

Representation

Page 29: Number System and Data Representation

29

3. Integer Representation (cont.)

For the purpose of computer storage and processing, only binary digits (0 and 1) may be used to represent numbers (negative or positive).

For a 8-bit number, there are 28 =256 possible bit patterns.

For unsigned number, we can represent 0 to 255 using 8-bit number.

For signed number, the most significant (leftmost) bit usually used as a sign bit. ( 0 for positive and 1 for negative number).

Page 30: Number System and Data Representation

30

Integer Representation (cont.)

There are several alternative conventions used to represent negative integers. Some of them are:

Signed magnitude

One’s complement

Two’s complement

Page 31: Number System and Data Representation

31

Signed Magnitude Also know as “sign and magnitude,” the

leftmost bit is the sign and the rest are magnitude0 = positive1 = negative

Sign Magnitude

Integer Representation (cont.)

Page 32: Number System and Data Representation

32

Example (for 8-bit number)+25d = 0 0011001b-25d = 1 0011001b

Largest number is +127 and smallest number is –127

Problems:Two representations for zero:+0 = 00000000b-0 = 10000000b

Integer Representation (cont.)

Signed Magnitude (cont.)

Page 33: Number System and Data Representation

33

One’s Complement The leftmost bits is the sign ( 0 = positive, 1 =

negative) Negative number is obtained by complementing

each bit from 0 to 1 or from 1 to 0 Example (8-bit number):

+25d = 00011001b-25d = 11100110b

Two representation of zero: +0d = 00000000b and -0d = 11111111

Largest number is +127 and smallest number is -127

Integer Representation (cont.)

Page 34: Number System and Data Representation

34

The leftmost bit is the sign bit (0=positive, 1 = negative)

Negative of the number is obtained by adding 1 to the one’s complement negative,

Example(8-bit number):+25d = 00011001b-25d = 11100111b

One representation for zero: 0000000b Largest number is +127 and smallest

number is -128

Two’s complement

Integer Representation (cont.)

Page 35: Number System and Data Representation

35

Range in Integer Representation For n bit number, highest integer value can be

represent is 2n-1 -1.

Highest value Lowest Value

Signed Magnitude 2 n-1-1 -(2 n-1-1)

One’s Complement

2 n-1-1 -(2 n-1-1)

Two’s Complement

2 n-1-1 -(2 n-1)

Integer Representation (cont.)

Page 36: Number System and Data Representation

36

Number System Data Representation Integer

Representation