27
1 CS120: Lecture 2 MP Johnson Hunter College [email protected]

CS120: Lecture 2

  • Upload
    presley

  • View
    29

  • Download
    0

Embed Size (px)

DESCRIPTION

CS120: Lecture 2. MP Johnson Hunter College [email protected]. Agenda: data. Review ops/gates Abstract storage: flipflops Storage methods representation: Test Images Sound Numbers Positive Negative Fractions Compression. Circuits as memory. - PowerPoint PPT Presentation

Citation preview

Page 1: CS120: Lecture 2

1

CS120: Lecture 2

MP Johnson

Hunter College

[email protected]

Page 2: CS120: Lecture 2

2

Agenda: data

• Review ops/gates• Abstract storage: flipflops• Storage methods• representation:

– Test– Images– Sound– Numbers

• Positive• Negative• Fractions

• Compression

Page 3: CS120: Lecture 2

3

Circuits as memory

• Flipflop: special circuit that can store data– 1 bit per FF

To store, send pulse in top or bottom (0 is ddf)

Go through

Page 4: CS120: Lecture 2

4

Another FF

Go through

Page 5: CS120: Lecture 2

5

circuits

• Q: where do inputs come from?

• A: other circuits!

• Connect worker circuit to mem circuit

• This kind of mem is in RAM or maybe CPU– Fast: measured in ns– Fast everywhere – “random”– But Requires constant power

Page 6: CS120: Lecture 2

6

Memory cells arranged by address

Page 7: CS120: Lecture 2

7

Metric units

• “Kilo-” normally means 1,000;Kilobyte = 210 = 1024

• “Mega-” normally means 1,000,000;Megabyte = 220 = 1,048,576

• “Giga-” normally means 1,000,000,000;Megabyte = 230 = 1,073,741,824

Page 8: CS120: Lecture 2

8

• Hard drive: Disk spins, head moves– Partly mechanical!– Usually larger, but slower

• Measured in ms• Time depends somewhat on location

Other (perm) kinds of mem

Page 9: CS120: Lecture 2

9

Other (perm) kinds of mem

• Optical: CD/DVD– Slower, less random– Read-only/read-once

• Flash: USB, MP3• Tape: very slow,

sequential

Page 10: CS120: Lecture 2

10

Storage devices

• Hardware varies a lot• Q: what stays the same?• A: all store bits / 1-of-2 choices• Q: why not base 3 or base 10?• A: easier!• High (voltage) v. low or pos v neg or 0 v 1• High v. low v. medium

• Q: why do we ever use base 10?

Page 11: CS120: Lecture 2

11

Claim: data = nums = bits

• Eg, letters: can’t write ‘A’ on a HD

• Q: what to do?

• A: pick some num to rep ‘A’– Turns out: ‘A’ = 65, ‘B’ = 66– ANSI’s ASCII

• Q: but how to rep 65?– Can’t write num 65 on a HD

• A: write 65 in binary

Page 12: CS120: Lecture 2

12

base

• mathematically, any base will do

• On machine, must use base 2:– 65 = 6*10 + 5*1

= 1*64 + 1*1= 1*2^5 + 1*2^0= 1000001b

65 + 1 = 1000001 + 1 = 1000010

Page 13: CS120: Lecture 2

13

ANSI• ANSI only uses 7 bits (128 vals)• Insert a 1 at front to get 8 bits = 1 byte (255)

• Usually: think in terms of bytes, not bits• Q: what about negatives, fractions?• A: next time…

Page 14: CS120: Lecture 2

14

hex

• Sometimes base-16 is used for as shorthand– 1 base-16 val = 4 bits

• Also octal

Page 15: CS120: Lecture 2

15

Rep’ing images?

• One way:– Bitmaps (.bmp)– b/w: 2-d table of brightness values

• Pixel = picture element

– Col: one table each of r/g/b– Size: 1000*1000*3 = 3MB!

• Another:– Vector methods…

Page 16: CS120: Lecture 2

16

Rep’ing sounds?• One way:

– Sample soundwave ampl at intervals– Phones: 8000/s– CD: 44,1000/s

• Another:– MIDI– For 10s constant tone, record tone + length

Page 17: CS120: Lecture 2

17

Data compression

• NB: vectors and MIDI sound smarter

• But whatever you do, must still be stored as bits

• Must find a way to encode these instructions as bits

• Harder than storing directly!

Page 18: CS120: Lecture 2

18

Base 2 v. base 10

Page 19: CS120: Lecture 2

19

Convert base10 base2

• Alg: while x is not 0– Write x%2 to right– Set x = x/2

Page 20: CS120: Lecture 2

20

Integers with bits

• Unsigned (non-neg): just base2• Signed:

0. Just use sign bit• How to add/sub?

1. 1’s comp– How to add/sub?– Two 0’s

2. 2’s comp– How to add/sub?– See app. B for neg, add circuits

3. Also: excess notation (skip?)

Page 21: CS120: Lecture 2

21

Fractions in binary (naïve)

Page 22: CS120: Lecture 2

22

IEEE floating-pt standard

Page 23: CS120: Lecture 2

23

IEEE floats

• Used for all fractions in C/C++/Java

• Strength: very large range (billions)

• Weakness: merely approximate– Can depend on order!

Page 24: CS120: Lecture 2

24

Compression

• Saw MIDI for sound• Saw vectors for images

• Other methods:– Relative methods for images (why works?)

• GIF, JPEG

– Relative methods for video (why works?)• MPEG

– Run-length encoding– Frequency-based (why works?)– LZ (zip files)

Page 25: CS120: Lecture 2

25

Recognizing errors

• Idea: include extra info

• Parity bits:

Page 26: CS120: Lecture 2

26

Correcting errors• “Error-correcting codes”

• If only one bad bit, can recover,e.g., 010100

Page 27: CS120: Lecture 2

27

Future

• No class Tuesday

• Reading for Wednesday is on website

• Hw posted soon (email/web)