chapter 03 data representation. 2 chapter goals distinguish between analog and digital information...

34
Chapter 03 Data Representation

Upload: hilary-berniece-merritt

Post on 31-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

Chapter 03

Data Representation

Page 2: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

2

Chapter Goals

• Distinguish between analog and digital information

• Explain data compression and calculate compression ratios

• Explain the binary formats for negative and floating-point values

• Describe the characteristics of the ASCII and Unicode character sets

• Perform various types of text compression

Page 3: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

3

Chapter Goals

• Explain the nature of sound and its representation

• Explain how RGB values define a color• Distinguish between raster and vector graphics• Explain temporal and spatial video compression

Page 4: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

4

Data and Computers

Computers are multimedia devices,dealing with a vast array of information categories

Computers store, present, and help us modify

• Numbers• Text• Audio• Images and graphics• Video

Page 5: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

5

Data compression

Reduction in the amount of space needed to store the dataCompression ratio •The size of the compressed data divided by the size of the original data• Between 0 and 1 (0% and 100%)

Compression techniques can belossless, which means the data can be retrieved

without any loss of the original informationlossy, which means some information may be lost in

the process of compaction

Page 6: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

6

Analog and Digital Data

The world is infinite and continuous• Zeno’s paradox: “That which is in locomotion must arrive at the half-way stage before it arrives at the goal. ” — Aristotle, Physics VI:9

Computers are finite and discrete!

How do we represent an infinite world?

We represent enough of the world to satisfy our computational needs and our senses of sight and sound

Actually, there are analog computers!

Page 7: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

7

Analog and Digital Information

Information can be represented in one of two ways: analog or digital

Analog data

A continuous representation, analogous to the actual information it represents

Digital data

A discrete representation, breaking the information up into separate elements

Page 8: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

8

Analog and Digital Information

Figure 3.1 A mercury thermometer continually rises in direct proportion to the temperature

Thermometeris ananalog device

Page 9: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

9

Analog and Digital Information

Computers cannot work well with analog data, so we digitize the data

Digitize

Breaking data into pieces and representing those pieces separately

Why do we use binary to represent digitized data?• Price• Reliability (Remember Leibniz and Babbage!)

Page 10: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

10

Electronic Signals

Important facts about electronic signals• An analog signal continually fluctuates in

voltage up and down • A digital signal has only a high or low state,

corresponding to the two binary digits • All electronic signals (both analog and digital)

degrade as they move down a line• The voltage of the signal fluctuates due to

environmental effects

Page 11: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

11

Electronic Signals (Cont’d)

Periodically, a digital signal is reclocked to regain its original shape

Figure 3.2 An analog and a digital signal

Figure 3.3 Degradation of analog and digital signals

Page 12: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

12

Binary Representations

One bit can be either 0 or 1

One bit can represent two things (Why?)

Two bits can represent four things (Why?)

How many things can three bits represent?

How many things can four bits represent?

How many things can eight bits represent?

Page 13: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

Individual work: read entire Section 3.1

13

Page 14: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

14

Binary Representations

Bit combinations

Figure 3.4

Why does the number of combinations double

with every extra bit?

Page 15: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

15

Binary Representations

How many things can n bits represent?

What happens every time you increase the number of bits by one?

More advanced example: “one byte – two byte” representation

Page 16: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

16

Representing Negative Values

Signed-magnitude number representation

The sign represents the ordering, and the digits represent the magnitude of the number

Page 17: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

17

Representing Negative Values

There is a problem with the sign-magnitude representation: plus zero and minus zero

Solution:

“Complement” representation

Page 18: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

18

Ten’s complement

Using two decimal digits, represent 100 numbers

• If unsigned, the range would be …

let 1 through 49 represent 1 … 49

let 50 through 99 represent -50 … -1

Page 19: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

19

Ten’s complement

To perform addition, add the numbers and discard any carry

Now you try it

48 (signed-magnitude)- 147

How does it work inthe new scheme?

Page 20: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

20

Ten’s complement

A-B=A+(-B)

Add the negative of the second to the first

Try 4 - 4 -4- 3 +3 + -3

Page 21: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

21

Two’s Complement

(Vertical line is easier to read)

Do you notice something interesting about the left-most bit (MSB)?

Page 22: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

22

Two’s complement on 4 bits (k = 4)

Page 23: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

23

Two’s complement

Addition and subtraction are the same as in unsigned:

-127 1000 0001

+ 1 0000 0001

-126 1000 0010

But ignore any Carry out of the MSB:

-1 1111 1111

+ -1 1111 1111

-2 1111 1110

Page 24: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

Have a nice weekend!

Individual work:• Read and take notes → up to p.62, before Number overflow• End of chapter exercises 1- 6, 33, 40, 41

The first exam will be next Friday (Sept. 18), during class time.

Next Wednesday is review for exam.

24

Page 25: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

25

Two’s complement

Formula to compute the negative of a number on k digits:• for ten’s comp: -I = Negative(I) → 10k - I• for two’s comp: -I = Negative(I) → 2k - I

Practice: find the 8-bit two’s comp. representations of:

-1

-2

-3

-51

-130

0

Page 26: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

26

Two’s complement

Q: Given a number in two’s complement, how do we find its magnitude?

A: Just like for unsigned numbers, only MSB is subtracted!

Practice: find the magnitudes of the following two’s comp. numbers:

0000 0011

1000 0000

1000 0001

1000 0011

1001 0110

1111 1111

Page 27: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

27

What happens if the computed value won't fit in the given number of bits k?

Overflow

If k = 8 bits, adding 127 to 3 overflows 1111 1111

+ 0000 0011 0 1000 0010

… but adding -1 to 3 doesn’t!

Conclusion: overflow is specific to the representation (unsigned, sign-mag., two’s comp., floating point etc.)

Page 28: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

28

Overflow

Problems occur when mapping an infinite world onto a finite machine!

Page 29: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

29

Representing Real Numbers

Real numbers A number with a whole part and a fractional part

104.32, 0.999999, 357.0, and 3.14159

Positions to the right of the decimal point are the tenths, hundredths, thousandths etc:

10-1, 10-2 , 10-3 …

Page 30: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

30

Representing Real Numbers

Same rules apply in binary as in decimal

Decimal point is actually the radix point

Positions to the right of the radix point in binary are

2-1 (one half),

2-2 (one quarter),

2-3 (one eighth)

Page 31: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

31

Representing Real Numbers

A real value in base 10 can be defined by the following formula

The representation is called floating point because the number of digits is fixed but the radix point floats

Page 32: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

32

Representing Real Numbers

A binary floating-point value is defined by the

formula

sign * mantissa * 2exp

Page 33: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

33

Representing Real Numbers

Scientific notation A form of floating-point representation in which the decimal point is kept to the right of the leftmost digit

12001.32708 is 1.200132708E+4 in scientific notation

What is 123.332 in scientific notation?

What is 0.0034 in scientific notation?

Page 34: Chapter 03 Data Representation. 2 Chapter Goals Distinguish between analog and digital information Explain data compression and calculate compression

This was all the material for Friday’s exam: up to and including Section

3.2

• This presentation is available on the webpage

• Make sure you understand all the examples!

• Review Wednesday!34