Chapter 2:number System and Data Representation: Computer Organization and Architecture

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 36

COMPUTER ORGANIZATION AND

ARCHITECTURE

Chapter 2:Number System


and Data Representation

1
Chapter II Number System and Data
Representation

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

2
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 digit’s 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

5
Number Systems (cont.)
The Hexadecimal 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:

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

0000 = 0 1000 = 8
0001 = 1 1001 = 9
0010 = 2 1010 = A
0011 = 3 1011 = B
0100 = 4 1100 = C
0101 = 5 1101 = D
0110 = 6 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.

8
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
9
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 0
3/2 = 1 1
1/2 = 0 1 Most significant bit
=> 26d = 11010b
13
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 1
0.75 x 2 = 1.5 1
0.5 x 2 = 1.0 1
0 x2 = 0 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 9 -> 9
 26 / 16 = 1 10 -> A
 1 / 16 = 0 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 DE1 to binary
16

D E 1
= 1101 1110 0001
= 110111100001b
 To go from binary to hex, just reverse this
process
10010001 = 1001 0001 = 91
2 16

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 device-
specific functions.
 Example: char A=65 in decimal,41 in hex, 0100 0001 in
binary.
20
Data Representation (cont.)
Printable
Binary Decimal Hex Abbreviation Name/Meaning
Representation
0000 0000 0 0 NUL ␀ Null character
0000 0001
0000 0010
0000 0011
1
2
3
1
2
3
SOH
STX
ETX



Start of Header
Start of Text
End of Text
ASCII Control Characters
End of
0000 0100 4 4 EOT ␄ Transmission
0000 0101

0000 0110
5

6
5

6
ENQ

ACK


Enquiry
Acknowledgme
nt
The
Thefirst
firstthirty-two
thirty-twocodes
codes(numbers
(numbers
0000 0111
0000 1000
7
8
7
8
BEL
BS


Bell
Backspace 0-31
0-31decimal)
decimal)ininASCII
ASCIIare arereserved
reserved
0000 1001 9 9 HT ␉ Horizontal Tab
0000 1010
0000 1011
10
11
0A
0B
LF
VT


Line Feed
Vertical Tab
for
forcontrol
controlcharacters:
characters:codes
codesthat
that
0000 1100 12 0C FF ␌ Form Feed

0000 1101 13 0D CR ␍ Carriage return


may
maynotnotthemselves
themselvesrepresent
represent

information,
information,but butthat
thatare
areused
usedtoto
0000 1110 14 0E SO Shift Out
0000 1111 15 0F SI ␏ Shift In
Data Link
0001 0000

0001 0001
16

17
10

11
DLE

DC1


Escape
XON Device
Control 1
control
controldevices
devices(such
(suchas asprinters)
printers)
0001 0010 18 12 DC2 ␒
Device Control
2 that
thatmake
makeuse useofofASCII.
ASCII.For For
XOFF Device
0001 0011 19 13 DC3 ␓ Control 3
Device Control
example,
example,character
character1010represents
representsthe
the

"line
"linefeed"
feed"function
function(which
(whichcauses
causesaa
0001 0100 20 14 DC4 4
Negative
Acknowledgem
0001 0101

0001 0110
21

22
15

16
NAK

SYN


ent
Synchronous
Idle
printer
printertotoadvance
advanceitsitspaper),
paper),and
and
0001 0111 23 17 ETB ␗
End of Trans.
Block character
character27 27represents
representsthethe"escape"
"escape"
0001 1000 24 18 CAN ␘ Cancel
0001 1001
0001 1010
25
26
19
1A
EM
SUB


End of Medium
Substitute
key
keyfound
foundon onthe
thetop
topleft
leftof
ofcommon
common
keyboards.
0001 1011 27 1B ESC ␛ Escape
0001 1100

0001 1101
28

29
1C

1D
FS

GS


File Separator
Group
Separator
keyboards.
Record
0001 1110
0001 1111
30
31
1E
1F
RS
US


Separator
Unit Separator 21
0111 1111 127 7F DEL ␡ Delete
Data Representation (cont.)

ASCII Printable Characters


Code
Code3232isisthe
the"space"
"space"character,
character,denoting
denotingthe
thespace
space
between
betweenwords,
words,which
whichisisproduced
producedbybythe
thelarge
largespace
space
bar
barof
ofaakeyboard.
keyboard.

Codes
Codes3333to
to126
126are
arecalled
calledthe
theprintable
printablecharacters,
characters,
which
whichrepresent
representletters,
letters,digits,
digits,punctuation
punctuationmarks,
marks,
and
andaafew
fewmiscellaneous
miscellaneoussymbols.
symbols.

22
Data Representation (cont.)
ASCII Printable Characters
Binary Decimal Hex Graphic
0010 1110 46 2E .

0010 0000 32 20 (blank) (␠) 0010 1111 47 2F /

0010 0001 33 21 ! 0011 0000 48 30 0

0010 0010 34 22 " 0011 0001 49 31 1

0011 0010 50 32 2
0010 0011 35 23 #
0011 0011 51 33 3
0010 0100 36 24 $
0011 0100 52 34 4
0010 0101 37 25 %
0011 0101 53 35 5

0010 0110 38 26 & 0011 0110 54 36 6

0010 0111 39 27 ' 0011 0111 55 37 7

0011 1000 56 38 8
0010 1000 40 28 (
0011 1001 57 39 9
0010 1001 41 29 )
0011 1010 58 3A :
0010 1010 42 2A *
0011 1011 59 3B ;

0010 1011 43 2B + 0011 1100 60 3C <

0010 1100 44 2C , 0011 1101 61 3D =

0011 1110 62 3E >
0010 1101 45 2D -
0011 1111 63 3F ?
23
Data Representation (cont.)
ASCII Printable Characters (cont.)
Binary Decimal Hex Graphic
0100 1111 79 4F O
0100 0000 64 40 @
0101 0000 80 50 P
0100 0001 65 41 A
0101 0001 81 51 Q

0100 0010 66 42 B
0101 0010 82 52 R

0100 0011 67 43 C 0101 0011 83 53 S

0100 0100 68 44 D 0101 0100 84 54 T

0100 0101 69 45 E 0101 0101 85 55 U

0100 0110 70 46 F 0101 0110 86 56 V

0100 0111 71 47 G 0101 0111 87 57 W

0100 1000 72 48 H 0101 1000 88 58 X

0100 1001 73 49 I 0101 1001 89 59 Y

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

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
One’s complement
Two’s 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 = 0 0011001b
-25d = 1 0011001b
 Largest number is +127 and smallest number is
–127
 Problems:Two representations for zero:
+0 = 00000000b
-0 = 10000000b

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

33
Integer Representation (cont.)
Two’s complement
 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
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 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
)

35
 Number System
 Data Representation
 Integer Representation

36

You might also like