Вы находитесь на странице: 1из 36

COMPUTER ORGANIZATION AND ARCHITECTURE

Chapter 2:Number System and Data Representation

Chapter II Number System and Data Representation

1. Number System
2. Data Representation 3. Integer Representation

1. Number Systems
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
3

Number Systems (cont.)


The 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 digits position:
4728 = (4 x 103) + (7 x 102) + (2 x 101) + (8 x 100)
4

Number Systems (cont.)


The Binary System
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

Number Systems (cont.)


The Hexadecimal System
A computers 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:
6

Number Systems (cont.)


The Hexadecimal System (cont.) 0000 = 0 1000 = 8

0001 = 1
0010 = 2 0011 = 3

1001 = 9
1010 = A 1011 = B

0100 = 4
0101 = 5 0110 = 6

1100 = C
1101 = D 1110 = E

0111 = 7

1111 = F
7

Number Systems (cont.)


The Hexadecimal 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.

Number Systems (cont.)


Decimal 0 1 2 Binary 0000 0001 0010 Hexadecimal 0 1 2

3
4 5 6 7 8 9 10 11 12 13 14 15

0011
0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

3
4 5 6 7 8 9 A B C D E F

Number Systems (cont.)


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

10

Number Systems (cont.)


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

11

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

12

Number Systems (cont.)


Converting Decimal to Binary

Decimal can be converted in to a binary systems with the Remainder Method Example: Convert 26d to base 2 26/2 = 13 0 Least significant bit 13/2 = 6 1
6/2 = 3/2 = 1/2 = => 26d = 11010b
13

3 1 0

0 1 1 Most significant bit

Number Systems (cont.)


Converting Decimal to Binary (Floating point number)

How about floating point number? E.g.: Convert 0.875d into base 2 number.
0.875 x 2 = 1.75 0.75 x 2 = 1.5 0.5 0 x 2 = 1.0 x2 = 0 1 1 1 0

=> 0.875d = 0.1110b


14

Number Systems (cont.)


Converting Decimal to Hex Decimal can be converted into a hex with the Remainder Method Example: Convert 425d to base 16
425 / 16 = 26 / 16 = 1 / 16 = 26 1 0 9 -> 9 10 -> A 1 -> 1

=> 425d = 1A9h

15

Number Systems (cont.)


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 process
100100012 = 1001 0001 = 9116
16

1. Number System

2. Data Representation
3. Integer Representation

17

2. Data Representation
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.)
18

Data Representation (cont.)


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)

19

Data Representation (cont.) 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 devicespecific functions. Example: char A=65 in decimal,41 in hex, 0100 0001 in binary.
20

Data Representation (cont.)


Binary 0000 0000 0000 0000 0000 0001 0010 0011 Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Hex 0 1 2 3 4 5 6 7 8 9 0A 0B 0C 0D 0E 0F 10 11 12 13 14 Abbreviation NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI DLE DC1 DC2 DC3 DC4 Printable Representation Name/Meaning Null character Start of Header Start of Text End of Text End of Transmission Enquiry Acknowledgme nt Bell Backspace Horizontal Tab Line Feed Vertical Tab Form Feed Carriage return Shift Out Shift In Data Link Escape XON Device Control 1 Device Control 2 XOFF Device Control 3 Device Control 4 Negative Acknowledgem ent Synchronous Idle End of Trans. Block Cancel End of Medium Substitute Escape File Separator Group Separator Record Separator Unit Separator Delete

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.
21

0000 0100 0000 0101 0000 0000 0000 0000 0000 0000 0000 0110 0111 1000 1001 1010 1011 1100

0000 1101 0000 1110 0000 1111 0001 0000 0001 0001 0001 0010 0001 0011 0001 0100

0001 0101 0001 0110 0001 0001 0001 0001 0001 0001 0111 1000 1001 1010 1011 1100

21 22 23 24 25 26 27 28 29 30 31 127

15 16 17 18 19 1A 1B 1C 1D 1E 1F 7F

NAK SYN ETB CAN EM SUB ESC FS GS RS US DEL

0001 1101 0001 1110 0001 1111 0111 1111

Data Representation (cont.)


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

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

Data Representation (cont.)


ASCII Printable Characters
Binary 0010 0000 0010 0001 0010 0010 0010 0011 0010 0100 0010 0101 0010 0110 0010 0111 0010 1000 0010 1001 0010 1010 0010 1011 0010 1100 0010 1101 Decimal 32 33 34 35 36 37 38 39 40 41 42 43 44 45 Hex 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D Graphic (blank) ( ) ! " # $
0011 0100 52 53 54 55 56 57 58 59 60 61 62 63 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 4 5 6 7 8 9 : ; < = > ? 0010 1110 0010 1111 0011 0000 0011 0001 0011 0010 0011 0011 46 47 48 49 50 51 2E 2F 30 31 32 33 . / 0 1 2 3

% & ' ( )

0011 0101 0011 0110 0011 0111 0011 1000 0011 1001 0011 1010

* + , -

0011 1011 0011 1100 0011 1101 0011 1110 0011 1111

23

Data Representation (cont.)


ASCII Printable Characters (cont.)
Binary 0100 0000 0100 0001 0100 0010 0100 0011 0100 0100 0100 0101 0100 0110 0100 0111 0100 1000 0100 1001 0100 1010 0100 1011 0100 1100 0100 1101 0100 1110 Decimal 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 Hex 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E Graphic
0100 1111 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F O P Q R S T U V W X Y Z [ \ ] ^ _

@ A B C D E F G H I J K L

0101 0000 0101 0001 0101 0010 0101 0011 0101 0100 0101 0101 0101 0110 0101 0111 0101 1000 0101 1001 0101 1010 0101 1011 0101 1100 0101 1101

M N
0101 1110 0101 1111

24

Data Representation (cont.)


ASCII Printable Characters (cont.)
Binary 0110 0000 0110 0001 0110 0010 0110 0011 0110 0100 0110 0101 0110 0110 0110 0111 0110 1000 0110 1001 0110 1010 0110 1011 0110 1100 0110 1101 0110 1110 Decimal 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 Hex 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E Graphic ` a b c d e f g h i j k l m n 0110 1111 0111 0000 0111 0001 0111 0010 0111 0011 0111 0100 0111 0101 0111 0110 0111 0111 0111 1000 0111 1001 0111 1010 0111 1011 0111 1100 0111 1101 0111 1110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 6F 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E o p q r s t u v w x y z { | } ~

25

Data Representation (cont.)


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.
26

Data Representation (cont.)


BCD
In 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. 27

1. Number System 2. Data Representation

3. Integer Representation

28

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).

29

Integer Representation (cont.)


There are several alternative conventions used to represent negative integers. Some of them are: Signed magnitude Ones complement Twos complement

30

Integer Representation (cont.)


Signed Magnitude
Also know as sign and magnitude, the leftmost bit is the sign and the rest are magnitude
0 = positive 1 = negative
Sign Magnitude

31

Integer Representation (cont.)


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

Largest number is +127 and smallest number is 127 Problems:Two representations for zero:
+0 -0 = = 00000000b 10000000b

32

Integer Representation (cont.) Ones 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
33

Integer Representation (cont.) Twos complement


The leftmost bit is the sign bit (0=positive, 1 = negative) Negative of the number is obtained by adding 1 to the ones complement negative, Example(8-bit number):
+25d -25d = = 00011001b 11100111b

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

34

Integer Representation (cont.) Range in Integer Representation


For n bit number, highest integer value can be represent is 2n-1 -1.
Highest value Lowest Value

Signed Magnitude
Ones Complement Twos Complement

2
2 2

n-1-1

-(2
-(2 -(2

n-1-1)

n-1-1

n-1-1)

n-1-1

n-1)

35

Number System Data Representation Integer Representation

36

Вам также может понравиться