cs311-computer organizationinformation representationlecture 03-1 lecture 3 information...

25
CS311-Computer Organization Information Representation Lecture 03-1 Lecture 3 Lecture 3 Information Information Representation Representation

Upload: eustace-chambers

Post on 05-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-1

Lecture 3Lecture 3Information Information

RepresentationRepresentation

Lecture 3Lecture 3Information Information

RepresentationRepresentation

Page 2: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-2

Lecture 3: Lecture 3: Information RepresentationInformation Representation

Lecture 3: Lecture 3: Information RepresentationInformation Representation

In this lecture, we will study• What to think about when representing information in the computer

system• What is the meaning of the Internal Representation and the External

Representation ?• Internal Representation

– Representation of Numbers• Fixed point representation

» Sign plus magnitude» 1’s complement» 2’s Complement

• Floating point representation– Representation of Nonnumeric data

• External Representation– ASCII, EBCDIC, 6-bit BCD

• Chinese Remainder Representation

Page 3: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-3

Considerations forConsiderations forInformation RepresentationInformation Representation

Considerations forConsiderations forInformation RepresentationInformation Representation

• Storage Space(number of bits for a code)• Convenience for information interchange• Efficiency for information processing• Simplicity for conversion from/to decimal system• Precision of representation

Human MachinesCharacter, Decimal Number Code(binary)

Page 4: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-4

Internal and External Internal and External RepresentationsRepresentations

Internal and External Internal and External RepresentationsRepresentations

OtherComputer

Device

Human

ExternalRepresentation

ExternalRepresentation

ExternalRepresentation

CPUMemory

InternalRepresentation

Page 5: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-5

External Representation– ASCII, EBCDIC, 6-bit BCD, …

Internal Representation– Nonnumeric data

• Processing does not modify data - e.g. word processing simply exchange or ordering of letters

• Use identical internal and external representations – no need for conversion

– Numeric Data• Scientific Applications

– Range of number is wide - Internal representation for precision reason– Fast Calculation - Internal representation for speed reason– CPU bound - conversion of codes for infrequent I/O operations is acceptable

• Commercial Data Processing– High volume I/O - Code Conversion for I/O is not acceptable– Complex calculation is rare - external representation is acceptable

Internal and External Internal and External RepresentationsRepresentations

Internal and External Internal and External RepresentationsRepresentations

Page 6: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-6

Representation of Data Representation of Data StructuresStructures

Representation of Data Representation of Data StructuresStructures

There exists relationship between data– Predecessor and successor

– Superior, peer, subordinate

– membership

– etc

Storage of data in a 1-dimensional memory space– Representation of relationships in 1-dimensional memory

space is not unique

– Simple linear list, string, array, and other complex structures

Page 7: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-7

Internal Representation of Internal Representation of NumbersNumbers

Internal Representation of Internal Representation of NumbersNumbers

Roman Number Decimal Number - a non-positional number system - a positional number system+ I II III IIII V …

I II III IIII V VI ... II III IIII V VI VII ...III IIII V VI VII VIII …IIII V VI VII VIII VIIII …V VI VII VIII VIIII X …VI VII VIII VIIII X XI …

+ 0 1 2 3 4 5 6 7 8 90 0 1 2 3 4 5 6 7 8 91 1 2 3 4 5 6 7 8 9 102 2 3 4 5 6 7 8 9 10 113 3 4 5 6 7 8 9 10 11 124 4 5 6 7 8 9 10 11 12 135 5 6 7 8 9 10 11 12 13 146 6 7 8 9 10 11 12 13 14 157 7 8 9 10 11 12 13 14 15 168 8 9 10 11 12 13 14 15 16 179 9 10 11 12 13 14 15 16 17 18 Addition Table is infinite

Inefficient Impossible to build an Adder

Addition Table is finite Easy to convert to/from decimal Possible to build an Adder Smaller table implies cheaper to

build Adder - Binary

. . . . . .. . . . . .

. . . . . .. . . . . .. . . . . .. . . . . .

Page 8: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-8

Internal Representation of Internal Representation of Numbers Numbers

Internal Representation of Internal Representation of Numbers Numbers

Binary Code(Base 2)• Easy to convert to/from Decimal• Cheapest code to build ALU

Binary number is a positional number system which uses the smallest number of symbols

Positional Number System

Representation: AR = an an-1 … a1 a0 . a-1 … a-m

where 0 < ai < R, and R is the base or radix

n-1

Equivalent decimal value: V(AR) = ai . Ri

i = -m

Page 9: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-9

Fixed Point Number Fixed Point Number RepresentationRepresentation

Fixed Point Number Fixed Point Number RepresentationRepresentation

A number representation in which the location of the fractional point is fixed

Overflow

The number to be represented is either too large, or too small(underflow) that the number cannot be precisely represented with the given number of bits.

Complement of a number A(R-1)’s Complement(1’s Complement, when R=2)

- For each position, subtract the number from (R-1), or

- Base R representation of Rn - R-m - |A|

R’s Complement(2’s Complement, when R=2)

- Add 1 to the (R-1)’s complement, or

- If A=0, then 0, else base R representation of Rn - |A|

Page 10: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-10

B2 = bn bn-1 … b1 b0 . b-1 … b-m

bn: sign bit

bn-1 … b1 b0 . b-1 … b-m : magnitude bits

bn-1 … b1 b0 : Integer part

b-1 … b-m : Fractional part

Computer systems rarely use both Integer and fractional parts, instead most computers use either Integer(Integer machine) or Fractional(Fractional machine) part only

• Sign plus magnitude representation• (Sign plus) 1’s complement representation• (Sign plus) 2’s complement representation

Binary Number RepresentationBinary Number RepresentationBinary Number RepresentationBinary Number Representation

Page 11: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-11

Sign Plus Magnitude Sign Plus Magnitude RepresentationRepresentation

Sign Plus Magnitude Sign Plus Magnitude RepresentationRepresentation

B = bn bn-1 … b1 b0 . b-1 … b-m

bn: sign bitbn-1 … b1 b0 . b-1 … b-m : magnitude bits

n-1

VS(B) = (-1)bn bi . 2i

i = -m

Easy to convert to the negative numberRange of representation;

Max: 011 … 11 . 11 … 1 (2n - 2-m)Min: 111 … 11 . 11 … 1 -(2n - 2-m)

2 representations of zero;+0: 000 … 00 . 00 … 0- 0: 100 … 00 . 00 … 0

Page 12: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-12

1’s Complement Representation1’s Complement Representation1’s Complement Representation1’s Complement Representation

B = bn bn-1 … b1 b0 . b-1 … b-m

bn: sign bit

bn-1 … b1 b0 . b-1 … b-m : magnitude bits

n-1

V1(B) = bn(2-m - 2n) + bi . 2i

i = -m

• Range of representation;

Max: 011 … 11 . 11 … 1 (2n - 2-m)

Min: 100 … 00 . 00 … 0 -(2n - 2-m)

• 2 representations of zero;

+0: 000 … 00 . 00 … 0

- 0: 111 … 11 . 11 … 1

Page 13: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-13

2’s Complement Representation2’s Complement Representation2’s Complement Representation2’s Complement Representation

B = bn bn-1 … b1 b0 . b-1 … b-m

bn: sign bit

bn-1 … b1 b0 . b-1 … b-m : magnitude bits n-1

V2(B) = -bn 2n + bi . 2i

i = -m

• Range of representation;Max: 011 … 11 . 11 … 1 (2n - 2-m)Min: 100 … 00 . 00 … 0 -2n

• Representations of zero;000 … 00 . 00 … 0

Page 14: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-14

ComparisonComparisonComparisonComparison

• Easiness of negative conversion– S+M > 1’s Complement > 2’s Complement

• Hardware– S+M: Need an Adder and a Subtractor for addition– 1’s and 2’s complement: Need only an Adder

• Speed of Arithmetic– 2’s Complement > 1’s Complement (end-around carry)

• Recognition of zero– 2’s Complement is fast

Page 15: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-15

Time OutTime Out

• 화가가 화랑 주인에게 자기 그림에 대해 관심을 보이는 사람이 없더냐고 물었다 .

• 화랑 주인이 대답했다 . “ 좋은 소식도 있고 , 나쁜 소식도 있지요 .”

• “ 좋은 소식은 내가 어떤 손님에게 당신이 죽고 나면 당신 그림 값이 크게 오를 것이라고 했더니 그 사람이 당신 그림을 몽땅 산거지요 .”

• “ 나쁜 소식은 그 손님이 당신의 주치의라는 것입니다 .”

Page 16: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-16

Floating Point RepresentationFloating Point RepresentationFloating Point RepresentationFloating Point Representation

19,850,000,000,000.000,000,000,034,82

Fixed point representation has the precision problem

Various representations of a very large or very small numbers;1,985 x 1010 can be represented as

0.1985 x 1014, 1.985 x 1013, 19.85 x 1012, 198.5 x 1011, …0.3482 x 10-10 can be represented as

3.482 x 10-11, 34.82 x 10-12, 348.2 x 10-13, 3,482 x 10-14, …

Floating Point Number: FF = AB

bn ak ak-1 … a0 bn-1 … b1 b0 . b-1 … b-m

sign exponent mantissa

Equivalent Decimal Value VF(F) = V(B) x 2V(A)

Page 17: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-17

Floating Point Number:Floating Point Number:

Representation of ZeroRepresentation of Zero

Floating Point Number:Floating Point Number:

Representation of ZeroRepresentation of Zero• Representation of Zero

– Zero• Mantissa = 0

– Real Zero• Mantissa = 0• Exponent: Smallest number that can be represented with given bits• 00 … 0 is most suitable representation• Needs to add Bias to the exponent value so that the smallest exponent

can be represented with 00…0Example: Assume 3-bit exponent

+3 011+2 010+1 001+0 000-0 111-1 110-2 101-3 100 100+ bias =000 Bias = 100

+100

111110101100011010001

Page 18: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-18

• Normal Form– Unified representation makes the comparison of numbers easy

– A representation that represents the given number most precisely by utilizing the most significant bit of mantissa

– e.g. Mantissa: Fractional representation with 4 decimal digits

Floating Point Number:Floating Point Number: NormalizationNormalization

Floating Point Number:Floating Point Number: NormalizationNormalization

37.26 0.3726 x 102 , 0.0372 x 103, 0.0037 x 104, 0.0003 x 105

Normal Form

S Exponent Mantissa

+ 2 .3726+ 3 .0372+ 4 .0037+ 5 .0003 . . .

Significant bit(s) is(are) wasted

Page 19: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-19

Internal Number Representation:Internal Number Representation:

Decimal RepresentationDecimal RepresentationInternal Number Representation:Internal Number Representation:

Decimal RepresentationDecimal Representation

• Arithmetic with Decimal Numbers

– No need to convert between decimal and other representations

• Commercial data processing applications

BCD Decimal

0000 00001 10010 20011 30100 40101 50110 60111 71000 81001 91010 -1011 -1100 -1101 -1110 -1111 -

• 1 digit log2 10 = 4 4-bit BCD– Unused code space– Slow arithmetic

Page 20: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-20

BCD(Binary Coded Decimal)– 4-bit code with 8, 4, 2, 1 weight on each bit (8421 code)– Difficult to convert to 9’s complement for the negative number

representation 2421 code, 84-2-1 code, excess 3 code for this purpose

Decimal Number Representation:Decimal Number Representation:

BCDBCDDecimal Number Representation:Decimal Number Representation:

BCDBCD

Decimal BCD 2421 84-2-1 excess 30 0000 0000 0000 00111 0001 0001 0111 01002 0010 0010 0110 01013 0011 0011 0101 01104 0100 0100 0100 0111 9’s complement5 0101 1011 1011 1000 representation6 0110 1100 1010 10017 0111 1101 1001 10108 1000 1110 1000 10119 1001 1111 1111 1100

Page 21: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-21

Totem in SunriseTotem in Sunrise

Page 22: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-22

• 6-bit BCD– 4-bit BCD + 2 bits

– Representation of numeric as well as nonnumeric symbols

– Capital and Small English letters are not distinguishable

– Suitable for computers with the word length of multiples of 6

• ASCII– Representation of 128 letters with 7 bits

– 8-bit ASCII <= 7-bit ASCII + 1 parity bit

• EBCDIC– 8-bit code

Nonnumeric RepresentationNonnumeric RepresentationNonnumeric RepresentationNonnumeric Representation

Page 23: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-23

Internal Representation of Numbers:Internal Representation of Numbers:

Chinese Remainder TheoremChinese Remainder TheoremInternal Representation of Numbers:Internal Representation of Numbers:

Chinese Remainder TheoremChinese Remainder Theorem

Conversion to decimal n

Let Nj = mi i=1, i= j

n

A = | Ni | ai / Ni |mi |M , where |X|M represents X modulo M i=1

Chinese Remainder TheoremA set of n relatively prime numbers: m1, m2, … , mn

A set of remainders {a1, a2, … , an} uniquely determines an integer A in the range of 0 < A < M, where

n

M = mi

i=1

Page 24: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-24

A=23;

Chinese Remainder Chinese Remainder RepresentationRepresentation

Chinese Remainder Chinese Remainder RepresentationRepresentation

A = (1, 2, 3)

m1 = 2, m2 = 3, m3 = 5; M = 2 x 3 x 5 = 30 0 < 23 < 30

a1 = |23|2 = 1a2 = |23|3 = 2a3 = |23|5 = 3

Conversion to decimal:N1 = m2 x m3 = 3 x 5 = 15N2 = m1 x m3 = 2 x 5 = 10N3 = m1 x m2 = 2 x 3 = 6

A = |(15 x |1/15|2) + 10 x (|2/10|3) + 6 x (|3/6|5) |30

= |(15 x |1/1|2) + 10 x (|2/1|3) + 6 x (|3/1|5) |30

= |15 + 20 + 18|30 = |53|30 = 23

Page 25: CS311-Computer OrganizationInformation RepresentationLecture 03-1 Lecture 3 Information Representation

CS311-Computer Organization Information Representation Lecture 03-25

• Very compact code - mi-remainders– Allows to calculate with smaller numbers

– Faster with smaller numbers

Significance of Chinese Significance of Chinese Remainder RepresentationRemainder Representation

Significance of Chinese Significance of Chinese Remainder RepresentationRemainder Representation

• mi-complement arithmetic is possible• Difficult to compare values of numbers• No carries to propagate between mi-remainders

(although we have to consider the carry propagation within an mi-remainder)• Division is extremely difficult

We have a 32-bit computer.Assume that we have to deal with a very large fixed point number which can not be fitted into a 32-bit register.If we select a set of prime numbers that can be represented with 32 bits,the number that we have to deal with can be represented with a code consists of a set of 32-bit numbers.