Chapter 1: Data Representation Dr Mohamed Menacer Taibah University 2007-2008.

Post on 29-Dec-2015

223 views 0 download

Tags:

Transcript of Chapter 1: Data Representation Dr Mohamed Menacer Taibah University 2007-2008.

Chapter 1:Chapter 1:Data RepresentationData Representation

Dr Mohamed MenacerDr Mohamed MenacerTaibah UniversityTaibah University

2007-20082007-2008

Bits are just bits (0,1)Bits are just bits (0,1) conventions define relationship between bits and numbersconventions define relationship between bits and numbers

Binary integers (base 2)Binary integers (base 2) 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001...0000 0001 0010 0011 0100 0101 0110 0111 1000 1001...

decimal: 0, …, 2decimal: 0, …, 2nn-1-1

Of course it gets more complicated:Of course it gets more complicated: bit strings arebit strings are finite finite, but , but

for somefor some fractions fractions and and real real numbers, finitely many bits is not numbers, finitely many bits is not enough, so enough, so overflowoverflow & & approximationapproximation errors: e.g., represent 1/3 as binary! errors: e.g., represent 1/3 as binary!

negativenegative integers integers

How do we represent negative integers?How do we represent negative integers? which bit patterns will represent which integers?which bit patterns will represent which integers?

NumbersNumbers

n bits

From Essentials of Computer Architecture by Douglas E. Comer. ISBN 0131491792. © 2005 Pearson Education, Inc. All rights reserved.

From Essentials of Computer Architecture by Douglas E. Comer. ISBN 0131491792. © 2005 Pearson Education, Inc. All rights reserved.

From Essentials of Computer Architecture by Douglas E. Comer. ISBN 0131491792. © 2005 Pearson Education, Inc. All rights reserved.

From Essentials of Computer Architecture by Douglas E. Comer. ISBN 0131491792. © 2005 Pearson Education, Inc. All rights reserved.

IBM's 8-bit extension of the 4-bit Binary Coded Decimal encoding of digits 0-9 (0000-1001), for character encoding.

From Essentials of Computer Architecture by Douglas E. Comer. ISBN 0131491792. © 2005 Pearson Education, Inc. All rights reserved.

From Essentials of Computer Architecture by Douglas E. Comer. ISBN 0131491792. © 2005 Pearson Education, Inc. All rights reserved.

From Essentials of Computer Architecture by Douglas E. Comer. ISBN 0131491792. © 2005 Pearson Education, Inc. All rights reserved.

From Essentials of Computer Architecture by Douglas E. Comer. ISBN 0131491792. © 2005 Pearson Education, Inc. All rights reserved.

From Essentials of Computer Architecture by Douglas E. Comer. ISBN 0131491792. © 2005 Pearson Education, Inc. All rights reserved.

From Essentials of Computer Architecture by Douglas E. Comer. ISBN 0131491792. © 2005 Pearson Education, Inc. All rights reserved.

From Essentials of Computer Architecture by Douglas E. Comer. ISBN 0131491792. © 2005 Pearson Education, Inc. All rights reserved.

Floating PointFloating Point

We need a way to representWe need a way to represent numbers with fractions, e.g., numbers with fractions, e.g., 3.14163.1416 very small numbers (in absolute value), e.g., very small numbers (in absolute value), e.g., .00000000023.00000000023 very large numbers (in absolute value) , e.g., very large numbers (in absolute value) , e.g., –3.15576 * 10–3.15576 * 104646

Representation:Representation:

scientificscientific: sign, exponent, significand form:: sign, exponent, significand form:

(–1)(–1)signsign * *significand *significand *22exponent exponent . E.g., . E.g., –101.001101 * 2–101.001101 * 2111001111001

more bits for more bits for significandsignificand gives more accuracy gives more accuracy

more bits for more bits for exponentexponent increases range increases range

binary point

From Essentials of Computer Architecture by Douglas E. Comer. ISBN 0131491792. © 2005 Pearson Education, Inc. All rights reserved.

From Essentials of Computer Architecture by Douglas E. Comer. ISBN 0131491792. © 2005 Pearson Education, Inc. All rights reserved.

Scales, Units, and ConventionsScales, Units, and Conventions

Term

K (kilo-)

M (mega-)

G (giga-)

T (tera-)

10 3

10 6

10 9

10 12

2 10 = 1024

2 20 = 1,048,576

2 30 = 1,073,741,824

2 40 = 1,099,511,627,776

Normal Usage As a power of 2

Term Usage

m (milli-)

(micro-)

n (nano-)

p (pico-)

10 -3

10 -6

10 -9

10 -12

Units: Bit (b), Byte (B), Nibble, Word (w), Double Word, Long Word Second (s), Hertz (Hz)

Powers of 2 are used to describe memory sizes.

Note the differences between usages. You should commit the powers of 2 and 10 to memory.