15
Foundations of CS William J. Taffe 12 September 2001 Data Representation and Storage 1. Algorithms tell processors how to manipulate data, TRANS but how do we store algorithms and data in a computer? 2. The Progression: we study how data is represented and stored we study how a processor can manipulate data we study how to represent algorithms to the computer (a programming language) we study the algorithms that instruct the processor in the solution of problems 3. We want to represent human knowledge in a computer Numbers (this was the goal of the earliest computers) Words (ideas … humans use written language to represent ideas) Images Sounds Smell Touch (haptic sense) Other? 4. BINARY codes … easier to build devices ON / OFF(transistor) CHARGED / UNCHARGED (capacitor) N-POLE / S-POLE (magnetic disk or tape) REFLECTED LIGHT / SCATTERED LIGHT (CDROM) 0 / 1 ... to represent the two states ... no meaning in themselves

Data Representation and Storage - Plymouth State University

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

Data Representation and Storage 1. Algorithms tell processors how to manipulate data, TRANS

but how do we store algorithms and data in a computer? 2. The Progression:

• we study how data is represented and stored • we study how a processor can manipulate data • we study how to represent algorithms to the computer (a

programming language) • we study the algorithms that instruct the processor in the solution of

problems 3. We want to represent human knowledge in a computer

• Numbers (this was the goal of the earliest computers) • Words (ideas … humans use written language to represent ideas) • Images • Sounds • Smell • Touch (haptic sense) • Other?

4. BINARY codes … easier to build devices

• ON / OFF (transistor) • CHARGED / UNCHARGED (capacitor) • N-POLE / S-POLE (magnetic disk or tape) • REFLECTED LIGHT / SCATTERED LIGHT (CDROM) • 0 / 1 ... to represent the two states ... no meaning in themselves

Page 2: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

5. ASCII Code ... binary representation of keyboard • Tables represent char, decimal equivalent TRANS • Can represent all “western” alphabet characters … 8-bit → 256

chars • Handout of the full code • Sometimes only given by 7 bits (7 bits -> 128 chars) • Codes 0..31 represent “nonprintable” ASCII control characters …

print “weird” things on the screen TRANS 6. Uniode … the “modern”, international representational code

• 16-bit → 65,536 chars … able to include all alphabets and scripts used today.

• Java uses unicode • First 8 bits (256 char) are the same as ASCII

7. Other Codes

• BCD ... Binary Coded Decimal ... just for numbers and capital letters

• EBCDIC …Extended Binary Coded Decimal Interchange Code (IBM Mainframes only)

8. Sequence of events from striking a key (eg. The letter “A” or the

number “1”) to storage and use in a computer

Page 3: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

9. Binary representation of our decimal numbers

Binary 0 = 010 1 = 110

but there is no 2 in binary ... only 1 and 2 Decimal Binary 0 0000 1 0001 2 0010 3 0011 4 0100 etc. 100 = 0001 20 = 1 101 = 0010 21 = 2 102 = 0100 22 = 4

Concept of Place Value • 0's place, 1's place, 2's place, etc • Therefore 7326 = 7X103 + 3X102 + 2X101 + 6X100 • 1101 = 1X23 + 1X22 + 0X21 + 1X20 = 8 + 4 + 0 + 1 = 13

10. Binary ⇔ Decimal Conversions

• Examples using concept of place value for binary numbers

Page 4: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

BINARY is hard on the eyes ... therefore we use decimal or hexadecimal to represent binary ... hex is easier

Decimal BINARY HEX 00 00000000 00 01 00000001 01 02 00000010 02 ... ... ... 09 00001001 09 10 00001010 0A … 14 00001110 0E 15 00001111 0F 16 00010000 10 17 00010001 11 ... 31 00011111 1F 32 00100000 20 33 00100001 21

11. Memory cells ... bit, nybble, byte, word ... define

• Modern cells store one byte 12. Cell has an address and content ... Post Office analogy TRANS

• RAM, ROM, Cache ... follow the post office box analogy

13. Hard disk, floppy disk TRANS • Tracks and sectors • Floppy disk holds 1.4 MB (high density) • (Our text ... 80 char/line X 40 lines/page X 600 pages =

1,920,000 chars = 1,920,000 bytes = 1,875KB = 1.8 MB • Hard disk holds 10 GB ... or about 6000 text books!

Question? How many textbooks (of the size of our text) would fit on a ZIP disk?

14. Graphics and Music … Codes are good for much of the work of

computers ... except for two things • graphics • music

Page 5: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

15. Graphic images

• CRT TRANS • Scan on monitor TRANS • RGB Guns and Shadow Mask TRANS • Memory stores a value for each RGB point in the Shadow Mask • Memory values are sent to appropriate electron gun which

creates the correct intensity of the electron beam 16. Representation of Colors TRANS

• Graphics ... bit maps • SVGA 800 X 600 ... 24 bits (224 colors) … 1.37 MB • floppy disk is 1.4 MB except that we use compression and

storage/compression techniques such as .jpg .gif .bmp .tif 17. Music … musical sound

• sampling and digitization • D -> A converters

18. Calculations ... codes are not good for addition and other arithmetic

operations. Therefore we transform numbers to a different format ... and it is the responsibility of the program to know what format to put things in!

19. Integer Addition of positive numbers

0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 10

reset the place and put one in the next level ... just like 9 + 1 = 10 0100 0111 1100 Never more complex ... because 0110 0111 0110 we never add more than two ------ ------ ------ numbers at a time ... explain 1010 1110 10010 adding a column.

20. Negative integers ... various methods to represent negative numbers

• Sign-magnitude • Two’s complement

Page 6: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

21. Sign-magnitude representation … most significant bit represents the

sign ... the other bits represent the number • XYYY = X000 -> X111 => 0..7 • XYYYYYY = X0000000 -> X1111111 => 0 .. 127 • All computers have a largest number • Advantage ... it’s easy • Disadvantage ... arithmetic rules don’t work

22. To form two's complement

• Form number in binary • If it is negative • Take its complement • Add one • If the MSB is 1, the number is negative • Advantage ... arithmetic rules work • Disadvantage ... it’s a bit more complicated to understand • An example -4

23. Subtractrion of Integer numbers • Not necessary … form negative of second number and add!

24. Floating Point … real numbers … 2.37 or 5.6X104

• Leave to the course in Computer Hardware

Page 7: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

Program Data

Computer

Output

Page 8: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

Page 9: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

Next TRANS

Page 10: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

Decimal Hex Binary Char Symbol Meaning

0 0 00000000 NULL Null 1 1 00000001 SOH Start of Heading 2 2 00000010 STX Start of Text 3 3 Etc. ♥ ETX End of Text 4 4 ♦ EOT End of Transmission 5 5 ♣ ENQ Enquiry 6 6 ACK Acknowledge 7 7 • BEL Bell 8 8 Etc. BS Backspace 9 9 HT Horizontal Tab

10 A LF Line Feed 11 B VT Vertical Tab 12 C FF Form Feed 13 D CR Carriage Return 14 E SO Shift Out 15 F SI Shift In 16 10 DLE Data Link Escape 17 11 DC1 Device Control 1 18 12 DC2 Device Control 2 19 13 DC3 Device Control 3 20 14 DC4 Device Control 4 21 15 NAK Negative Acknowledge 22 16 SYN Synchronous Idle 23 17 ETB End of Transmission Block 24 18 CAN Cancel 25 19 EM End of Medium 26 1A ESC Escape 27 1B FS File Separator 28 1C GS Group Separator 29 1D RS Record Separator 30 1E US Unit Separator 31 1F 00011111 DEL Delete

Page 11: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

Page 12: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

Page 13: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

Page 14: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001

Page 15: Data Representation and Storage - Plymouth State University

Foundations of CS William J. Taffe 12 September 2001