29
© 2005 Pearson Addison-Wesley. All rights reserved 1-1 CS101 Introduction to Computer Science Chapter 1: Data Storage Prof.Dr. Mehmet E. DALKILIÇ http://www.ube.ege.edu.tr/~dalkilic [email protected] Izmir University of Economics Faculty of Computer Science Fall 2005 Acknowlegement: Lecture Slides are based on the master slides of the text Glenn Brookshear, Computer Science an Overview, 8/E, Add-Wesley, 2005 © 2005 Pearson Addison-Wesley. All rights reserved 1-2 Chapter 1: Data Storage 1.1 Bits and Their Storage 1.2 Main Memory 1.3 Mass Storage 1.4 Representing Information as Bit Patterns 1.5 The Binary System 1.6 Storing Integers

CS101 Introduction to Computer Science Chapter 1: Data Storage

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS101 Introduction to Computer Science Chapter 1: Data Storage

1

© 2005 Pearson Addison-Wesley. All rights reserved1-1

CS101 Introduction to Computer Science Chapter 1: Data Storage

Prof.Dr. Mehmet E. DALKILIÇ

http://www.ube.ege.edu.tr/[email protected]

Izmir University of EconomicsFaculty of Computer Science

Fall 2005

Acknowlegement: Lecture Slides are based on the master slides of the text Glenn Brookshear, Computer Science an Overview, 8/E, Add-Wesley, 2005

© 2005 Pearson Addison-Wesley. All rights reserved1-2

Chapter 1: Data Storage

• 1.1 Bits and Their Storage• 1.2 Main Memory• 1.3 Mass Storage• 1.4 Representing Information as Bit Patterns• 1.5 The Binary System• 1.6 Storing Integers

Page 2: CS101 Introduction to Computer Science Chapter 1: Data Storage

2

© 2005 Pearson Addison-Wesley. All rights reserved1-3

Chapter 1: Data Storage (continued)

• 1.7 Storing Fractions• 1.8 Data Compression• 1.9 Communications Errors (will not cover)

© 2005 Pearson Addison-Wesley. All rights reserved1-4

Bits and their meaning

• Bit = Binary Digit = a symbol whose meaning depends on the application at hand.

• Some possible meanings for a single bit– Numeric value (1 or 0)– Boolean value (true or false)– Voltage (high or low)

Page 3: CS101 Introduction to Computer Science Chapter 1: Data Storage

3

© 2005 Pearson Addison-Wesley. All rights reserved1-5

Bit patterns

• All data stored in a computer are represented by patterns of bits:– Numbers– Text characters– Images– Sound– Anything else…

© 2005 Pearson Addison-Wesley. All rights reserved1-6

Boolean operations

• Boolean operation = any operation that manipulates one or more true/false values– Can be used to operate on bits

• Specific operations– AND– OR– XOR– NOT

Page 4: CS101 Introduction to Computer Science Chapter 1: Data Storage

4

© 2005 Pearson Addison-Wesley. All rights reserved1-7

Figure 1.1 The Boolean operations AND, OR, and XOR (exclusive or)

© 2005 Pearson Addison-Wesley. All rights reserved1-8

Gates

• Gates = devices that produce the outputs of Boolean operations when given the operations’ input values– Often implemented as electronic circuits– Provide the building blocks from which computers

are constructed

Page 5: CS101 Introduction to Computer Science Chapter 1: Data Storage

5

© 2005 Pearson Addison-Wesley. All rights reserved1-9

Figure 1.2 A pictorial representation of AND, OR, XOR, and NOT gates as well as their input and output values

© 2005 Pearson Addison-Wesley. All rights reserved1-10

Flip-flops

• Flip-flop = a circuit built from gates that can store one bit of data.– Has an input line which sets its stored value to 1– Has an input line which sets its stored value to 0– While both input lines are 0, the most recently

stored value is preserved

Page 6: CS101 Introduction to Computer Science Chapter 1: Data Storage

6

© 2005 Pearson Addison-Wesley. All rights reserved1-11

Figure 1.3 A simple flip-flop circuit

© 2005 Pearson Addison-Wesley. All rights reserved1-12

Figure 1.4 Setting the output of a flip-flop to 1

Page 7: CS101 Introduction to Computer Science Chapter 1: Data Storage

7

© 2005 Pearson Addison-Wesley. All rights reserved1-13

Figure 1.4 Setting the output of a flip-flop to 1 (cont’d)

© 2005 Pearson Addison-Wesley. All rights reserved1-14

Figure 1.4 Setting the output of a flip-flop to 1 (cont’d)

Page 8: CS101 Introduction to Computer Science Chapter 1: Data Storage

8

© 2005 Pearson Addison-Wesley. All rights reserved1-15

Figure 1.5 Another way of constructing a flip-flop

© 2005 Pearson Addison-Wesley. All rights reserved1-16

Other storage techniques

• Dynamic memory – must be replenished periodically – Example: capacitors

• Volatile memory – holds its value until the power is turned off – Example: flip-flops

• Non-volatile memory – holds its value after the power is off – Example: magnetic storage

• Read-only memory (ROM) – never changes –Examples: flash memory, compact disks

Page 9: CS101 Introduction to Computer Science Chapter 1: Data Storage

9

© 2005 Pearson Addison-Wesley. All rights reserved1-17

Hexadecimal notation

• Hexadecimal notation = a shorthand notation for streams of bits.– Stream = a long string of bits.– Long bit streams are difficult to make sense of.– The lengths of most bit streams used in a machine

are multiples of four.– Hexadecimal notation is more compact.

• Less error-prone to manually read, copy, or write

1-18

Figure 1.6 The hexadecimal coding system

Page 10: CS101 Introduction to Computer Science Chapter 1: Data Storage

10

© 2005 Pearson Addison-Wesley. All rights reserved1-19

Main memory: cells

• Cells = manageable units (typically 8 bits) into which a computer’s main memory is arranged.

• Byte = a string of 8 bits.• High-order end = the left end of the conceptual row

in which the contents of a cell are laid out.• Low-order end = the right end of the conceptual row

in which the contents of a cell are laid out.– Least significant bit = the last bit at the low-order end.

© 2005 Pearson Addison-Wesley. All rights reserved1-20

Figure 1.7 The organization of a byte-size memory cell

Page 11: CS101 Introduction to Computer Science Chapter 1: Data Storage

11

© 2005 Pearson Addison-Wesley. All rights reserved1-21

Main memory addresses

• Address = a “name” to uniquely identify one cell in the computer’s main memory

• The names for cells in a computer are consecutive numbers, usually starting at zero

• Cells have an order: “previous cell” and “next cell” have reasonable meanings

• Random Access Memory = memory where any cell can be accessed independently

© 2005 Pearson Addison-Wesley. All rights reserved1-22

Figure 1.8 Memory cells arranged by address

Page 12: CS101 Introduction to Computer Science Chapter 1: Data Storage

12

© 2005 Pearson Addison-Wesley. All rights reserved1-23

Measuring memory capacity: Not quite like the metric system

• Memories are designed to have 2n bytes.• “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;

Gigabyte = 230 = 1,073,741,824• Confusion: Suppose you buy a PC with 40 GB hard

disk; In fact, it is 40/1,073,741,824 = 37,3 Gigabyte

© 2005 Pearson Addison-Wesley. All rights reserved1-24

Mass Storage Systems

• Non-volatile; data remains when computer is off• Usually much bigger than main memory• Low cost• Typically “off line” that is removable from machine for

archival storage• Usually rotating disks

– Hard disk, floppy disk, CD-ROM– Much slower than main memory

• Data access must wait for seek time (head positioning)• Data access must wait for rotational latency

Page 13: CS101 Introduction to Computer Science Chapter 1: Data Storage

13

© 2005 Pearson Addison-Wesley. All rights reserved1-25

Figure 1.9 A disk storage system

© 2005 Pearson Addison-Wesley. All rights reserved1-26

Notes on the disk storage systems

• Average disk access time is equal to Average seek time +Average rotational delay +Data transfer time +Controller overhead

• Formatting: marking the locations of tracks and sectors magnetically

Page 14: CS101 Introduction to Computer Science Chapter 1: Data Storage

14

© 2005 Pearson Addison-Wesley. All rights reserved1-27

Figure 1.10 CD storage format

© 2005 Pearson Addison-Wesley. All rights reserved1-28

Notes on CD (Compact Disk) storage systems

• Reflective material covered with a clear protective coating

• Information recorded by creating variations on this reflective surface

• Read by a laser beam and light sensor• CD is a suitable storage medium for long, continuous

strings of data e.g., music• CD capacity approx. 600-700MByte• DVD (Digital Versatile Disks) ~Several GByte

– Constructed from multiple, semi-transparent layers that can be distinguished by a precisely focus laser

Page 15: CS101 Introduction to Computer Science Chapter 1: Data Storage

15

© 2005 Pearson Addison-Wesley. All rights reserved1-29

Figure 1.11 A magnetic tape storage mechanism

© 2005 Pearson Addison-Wesley. All rights reserved1-30

Notes on Magnetic Tape storage system

• Large Capacity ~many GigaBytes• Slowest of all storage mediums we have seen

– Within a segment sequential access– Only limited independent segments (i.e., limited

parallelism)• Used for archival (backup) storage

– DVD’s are catching up!

Page 16: CS101 Introduction to Computer Science Chapter 1: Data Storage

16

© 2005 Pearson Addison-Wesley. All rights reserved1-31

Comparing degrees of random access for Main Memory(MM), Magnetic Disks, Compact Disks, Magnetic Tape

• MM (also known as RAM: Random Access Memory) provides random access to any cell i.e., access time is independent from the cell location

• Magnetic disks provide random access only to entire sectors of data– Retrieving a sector involves seek and rotation times that vary i.e.,

dependent on the location• Compact Disks also provide random access to indiviual sectors

but delays are greater due to the additional time to locate the spiraling track and to adjust the rotation speed of the disk.

• Magnetic tapes are essentially sequential

© 2005 Pearson Addison-Wesley. All rights reserved1-32

Files

• File = the unit of data stored on a mass storage system.– Logical record and Field = natural groups of data within a

file e.g., data on an individual employee

• Physical record = a block of data conforming to the physical characteristics of the storage device.

• Buffer = main memory area sometimes set aside for assembling logical records or fields of a file

Page 17: CS101 Introduction to Computer Science Chapter 1: Data Storage

17

© 2005 Pearson Addison-Wesley. All rights reserved1-33

Figure 1.12 Logical records versus physical records on a disk

© 2005 Pearson Addison-Wesley. All rights reserved1-34

Figure 1.13 The message “Hello.” in ASCII

Page 18: CS101 Introduction to Computer Science Chapter 1: Data Storage

18

© 2005 Pearson Addison-Wesley. All rights reserved1-35

Representing text

• Each printable character (letter, punctuation, etc.) is assigned a unique bit pattern.– ASCII = 7-bit values for most symbols used in

written English text– Unicode = 16-bit values for most symbols used in

most world languages today– ISO proposed standard = 32-bit values

© 2005 Pearson Addison-Wesley. All rights reserved1-36

Representing numeric values

• Binary notation – uses bits to represent a number in base two– uses only digits of 0 and 1– Using n bits we can encode integers in 0 to 2n-1e.g., 16 bits encode values in the range 0 to 216-1=65535

• Limitations of computer representations of numeric values– Overflow – happens when a number is too big to be

represented• Example: 65500 + 41 can’t be represented in 16 bits

– Truncation – happens when a number is between two representable numbers

Page 19: CS101 Introduction to Computer Science Chapter 1: Data Storage

19

© 2005 Pearson Addison-Wesley. All rights reserved1-37

Figure 1.14 The sound wave represented by the sequence 0, 1.5, 2.0, 1.5, 2.0, 3.0, 4.0, 3.0, 0

© 2005 Pearson Addison-Wesley. All rights reserved1-38

Notes on Representing Sound

• Sample the amplitude of the sound signal at regular intervals – e.g., 8000 sample/sec for voice telecom – 44,100 sample/sec in music recordings

• each sample 16 bits (mono) or 32 bits (stereo) i.e., one second of stereo recording 44,100 x 32 > 1 million bits

– An alternative encoding system MIDI (Musical Instrument Digital Interface)

• encodes using much less storage – 3 bytes per second : storing what instrument is to play which

note how long

Page 20: CS101 Introduction to Computer Science Chapter 1: Data Storage

20

© 2005 Pearson Addison-Wesley. All rights reserved1-39

Figure 1.15 The base ten and binary systems

© 2005 Pearson Addison-Wesley. All rights reserved1-40

Figure 1.16 Decoding the binary representation 100101

Page 21: CS101 Introduction to Computer Science Chapter 1: Data Storage

21

© 2005 Pearson Addison-Wesley. All rights reserved1-41

Figure 1.17 An algorithm for finding the binary representation of a positive integer

© 2005 Pearson Addison-Wesley. All rights reserved1-42

Figure 1.18 Applying the algorithm in Figure 1.15 to obtain the binary representation of thirteen

Page 22: CS101 Introduction to Computer Science Chapter 1: Data Storage

22

© 2005 Pearson Addison-Wesley. All rights reserved1-43

Figure 1.19 The binary addition facts

Carry out the addition: 00111010 + 00011011 ?

© 2005 Pearson Addison-Wesley. All rights reserved1-44

Fractions in Binary notation

• We use radix point to accomodate fractional values– Same role as the decimal point in decimal notation– Integer part . Decimal part – e.g., 101.10 = five and a half i.e., 5,5– To add two fractional binary numbers

• Align the radix points and do addition as before e.g. 10.011 added to 100.11 produces 111.001

Page 23: CS101 Introduction to Computer Science Chapter 1: Data Storage

23

© 2005 Pearson Addison-Wesley. All rights reserved1-45

Figure 1.20 Decoding the binary representation 101.101

© 2005 Pearson Addison-Wesley. All rights reserved1-46

Representing Integers

• Unsigned integers can be represented in base two

• Signed integers = numbers that can be positive or negative– Two’s complement notation = the most popular

representation– Excess notation = another less popular

representation

Page 24: CS101 Introduction to Computer Science Chapter 1: Data Storage

24

© 2005 Pearson Addison-Wesley. All rights reserved1-47

Figure 1.21 Two’s complement notation systems

© 2005 Pearson Addison-Wesley. All rights reserved1-48

Figure 1.22 Coding the value -6 in two’s complement notation using four bits

Page 25: CS101 Introduction to Computer Science Chapter 1: Data Storage

25

© 2005 Pearson Addison-Wesley. All rights reserved1-49

Figure 1.23 Addition problems converted to two’s complement notation

© 2005 Pearson Addison-Wesley. All rights reserved1-50

Overflow in 2’s complement

• Suppose we use 4-bit 2’s complement numbers – Can represent inegers from -8 (1000) to +7 (0111)

• Want to add 7 and 6– 7 + 6 = 0111 + 0110

= 1101 (which is -3) OVERFLOW!!

Page 26: CS101 Introduction to Computer Science Chapter 1: Data Storage

26

© 2005 Pearson Addison-Wesley. All rights reserved1-51

Figure 1.24 An excess eight conversion table

© 2005 Pearson Addison-Wesley. All rights reserved1-52

Figure 1.25 An excess notation system using bit patterns of length three

Page 27: CS101 Introduction to Computer Science Chapter 1: Data Storage

27

© 2005 Pearson Addison-Wesley. All rights reserved1-53

Figure 1.26 Floating-point notation components

© 2005 Pearson Addison-Wesley. All rights reserved1-54

Figure 1.27 Coding the value 2 5⁄8

Page 28: CS101 Introduction to Computer Science Chapter 1: Data Storage

28

© 2005 Pearson Addison-Wesley. All rights reserved1-55

Figure 1.28 Decompressing xyxxyzy (5, 4, x)

© 2005 Pearson Addison-Wesley. All rights reserved1-56

Figure 1.29 The ASCII codes for the letters A and F adjusted for odd parity

Page 29: CS101 Introduction to Computer Science Chapter 1: Data Storage

29

© 2005 Pearson Addison-Wesley. All rights reserved1-57

Figure 1.30 An error-correcting code

© 2005 Pearson Addison-Wesley. All rights reserved1-58

Figure 1.31 Decoding the pattern 010100 using the code in Figure 1.30