C#2 - Data Storage
C#2 - Data Storage
Lecture slides are adapted/modified from slides provided by the textbook, Computer
Science: An Overview by J. Glenn Brookshear and Dennis Brylow
publisher Pearson
Data Storage
Bits and Their Storage
Main Memory
Representing Information as Bit Patterns
The Binary System
Storing Integers
Storing Fractions
Data Compression
Communications Errors
Mass Storage
2
Bits and Bit Patterns
Bit: Binary Digit (0 or 1)
Bit Patterns are used to represent information.
Numbers
Text characters
Images
Sound
And others
3
Boolean Operations
Boolean Operation: An operation that manipulates one
or more true/false values
Specific operations
AND
OR
XOR (exclusive or)
NOT
4
Boolean Operations
5
Gates
Gate: A device that computes a Boolean operation
Often implemented as (small) electronic circuits
Provide the building blocks from which computers are
constructed
VLSI (Very Large Scale Integration)
6
A pictorial representation of gates
7
Quiz
What are the names of these gates?
8
Quiz
What input bit patterns will cause the following circuit to
produce output of 1?
9
Flip-flops
Flip-flop: A circuit built from gates that can store one bit.
One input line is used to set its stored value to 1
One input line is used to set its stored value to 0
While both input lines are 0, the most recently stored value
is preserved
10
A simple flip-flop circuit
11
Setting the output of a flip-flop to 1
12
Setting the output of a flip-flop to 1
13
Setting the output of a flip-flop to 1
14
Quiz
Placing a 1 on the lower input of the flip-flop. What will
happen at the output?
15
Another flip-flop
16
Quiz
If upper input is 1 and lower input is 0, what is the
output?
17
Quiz
18
Activity
19
Hexadecimal Notation
Hexadecimal notation: A shorthand notation for long bit
patterns
Divides a pattern into groups of four bits each
Represents each group by a single symbol
Example: 1010 0011 becomes A3
20
The hexadecimal coding system
21
Quiz
What bit patterns are represented by the following
hexadecimal patterns?
5FD97
610A
ABCD
0100
22
MAIN MEMORY
Main Memory Cells
Cell: A unit of main memory (typically 8 bits
which is one byte)
Most significant bit: the bit at the left (high-order) end of
the conceptual row of bits in a memory cell
Least significant bit: the bit at the right (low-order) end of
the conceptual row of bits in a memory cell
24
The organization of a byte-size memory cell
25
Main Memory Addresses
Address: A “name” that uniquely identifies one
cell in the computer’s main memory
The names are actually numbers.
These numbers are assigned consecutively starting at zero.
Numbering the cells in this manner associates an order with
the memory cells.
26
Memory cells arranged by address
27
Memory Terminology
Random Access Memory (RAM): Memory in which
individual cells can be easily accessed in any order
Dynamic Memory (DRAM): RAM composed of volatile
memory
28
Measuring Memory Capacity
Kilobyte: 210 bytes = 1024 bytes
Example: 3 KB = 3 times 1024 bytes
Megabyte: 220 bytes = 1,048,576 bytes
Example: 3 MB = 3 times 1,048,576 bytes
Gigabyte: 230 bytes = 1,073,741,824 bytes
Example: 3 GB = 3 times 1,073,741,824 bytes
Terabyte
Petabyte
Exabyte
31
The message “Hello.” in ASCII
32
Representing Numeric Values
Binary notation: Uses bits to represent a number in base
two
Limitations of computer representations of numeric
values
Overflow: occurs when a value is too big to be represented
Truncation: occurs when a value cannot be represented
accurately
33
Representing Images
Bit map techniques
Pixel: short for “picture element”
RGB
Luminance and chrominance
Vector techniques
Scalable
TrueType and PostScript
34
Representing Sound
Sampling techniques
Used for high quality recordings
Records actual audio
MIDI
Used in music synthesizers
Records “musical score”
35
Representing Sound
37
THE BINARY SYSTEM
The Binary System
The traditional decimal system is based on powers of ten.
39
The base ten and binary systems
40
Decoding the binary representation
100101
41
Algorithm for finding the binary
representation of a positive integer
42
Applying the algorithm
13
43
The binary addition facts
44
Decoding the binary representation
48
Two’s complement notation systems
Leftmost bit: sign bit
49
Two’s complement notation systems
50
Coding the value -6 in two’s
complement notation using four bits
51
Addition problems converted to two’s
complement notation
52
Quiz
Convert each of the following two’s complement
representations to its equivalence base 10 form:
00011
01111
11100
11010
00000
10000
53
Quiz
Convert to two’s complement form using patterns of 8 bits:
6
-6
-17
13
-1
0
54
Quiz
What are the largest and smallest numbers that can be
stored if the machine uses bit patterns of the following
lengths?
A. four
B. six
C. eight
55
Min and max of signed integers
n minimum maximum
8 -27 = -128 27 - 1 = +127
16 -215 = -32,768 215 - 1 = +32,767
32 -231 = -2,147,483,648 231 - 1 = +2,147,483,647
64 -263 = - 263-1 =
9,223,372,036,854,775,808 +9,223,372,036,854,775,807
56
Min and max of unsigned integers
n Minimum Maximum
8 0 28 - 1 = 255
16 0 216 - 1 = 65,535
32 0 232 -1 = 4,294,967,295
64 0 264 - 1 = 18,446,744,073,709,551,615
57
An excess eight conversion table
58
An excess notation system
using bit patterns of length three
59
60
STORING FRACTIONS
Storing Fractions
Floating-point Notation: Consists of a sign bit, a
mantissa field, and an exponent field.
Mantissa: also fraction/significand
62
Floating-point notation components
63
Encoding the value 2 5 8
64
IEEE-754 32-bit Single-Precision
Floating-Point Numbers
Exponent: excess-127 (bias-127)
Fraction: implicit leading bit (before radix point).
65
IEEE-754 32-bit Single-Precision
Floating-Point Numbers
Suppose that IEEE-754 32-bit floating-point
representation pattern is 0 10000000 110 0000 0000
0000 0000 0000.
66
IEEE-754 32-bit Single-Precision
Floating-Point Numbers
Suppose that IEEE-754 32-bit floating-point representation
pattern is 1 01111110 100 0000 0000 0000 0000 0000.
67
Biểu diễn số thực (độ chính xác đơn)
00111001001101000000000000000000
11000000010010110000000000000000
68
IEEE-754 64-bit Double-Precision
Floating-Point Numbers
Exponent: excess-1023
Fraction: implicit leading bit (before radix point).
69
Min and Max of Floating-Point Numbers
70
DATA COMPRESSION
Data Compression
Lossy versus lossless
Run-length encoding
Frequency-dependent encoding
(Huffman codes)
Relative encoding
Dictionary encoding (Includes adaptive dictionary
encoding such as LZW encoding.)
72
Compressing Images
GIF: Good for cartoons
JPEG: Good for photographs
TIFF: Good for image archiving
73
Compressing Audio and Video
MPEG
High definition television broadcast
Video conferencing
MP3
Temporal masking
Frequency masking
74
COMMUNICATION ERRORS
Communication Errors
Parity bits (even versus odd)
Checkbytes
Error correcting codes
76
The ASCII codes for the letters A and F
adjusted for odd parity
77
Checkbyte
Set of parity bits
Each parity bit is scattered in the bit patterns
For example, a parity bit is associated with every
eighth bit in the bit patterns
Checksum
78
An error-correcting code
Hamming distance (of two bit patterns):
Number of bits in which the patterns differ.
Example:
Hamming(000000, 001111) = 4
Hamming(10101100, 01100100) = 3
79
An error-correcting code
80
Decoding the pattern 010100
81
Quiz
The following bytes were originally encoded using odd
parity. In which of them do you know that an error has
occurred?
82
Quiz
Using the error-correcting code presented before, decode
the following messages:
83
Quiz
Construct a code for the characters A, B, C, D using bit
patterns of length five so that the Hamming distance
between any two patterns is at least three.
84
MASS STORAGE
Mass Storage
On-line versus off-line
Typically larger than main memory
Typically less volatile than main memory
Typically slower than main memory
Typically lower cost than main memory
86
Mass Storage Systems
Magnetic Systems
Disk
Tape
Optical Systems
CD
DVD
Flash Technology
Flash Drives
Secure Digital (SD) Memory Card
87
Source: Wikipedia
88
Source: Wikipedia
89
Source: Wikipedia
90
A magnetic disk storage system
91
A magnetic disk storage system
Data stored on a spinning disk
Disk divided into concentric rings (sectors)
Read/write head moves from one ring to another while
disk spins
Access time depends on
Time to move head to correct sector
Time for sector to spin to data location
Fixed number of sectors are placed in a track.
Track sectors track
Disk sectors 92
A magnetic disk storage system
Seek time
Time needed to position the read/write head over the
correct track
Latency
Time for the beginning of the desired sector to rotate under
the read/write head
Transfer time
Time for the entire sector to pass under the read/write
head and have its contents read into or written from
memory
93
A magnetic disk storage system
Given:
Rotation speed = 7,200 rev/min=120 rev/sec = 8.33 msec/rev
Arm movement time = 0.02 msec to move to an adjacent track
On average, the read/write head must move about 300 tracks
Number of tracks/surface = 1,000
Number of sectors/track = 64
Number of bytes/sector = 1,024
Seek time
Best case = 0 msec;
Worst case = 999*0.02=19.98 msec
Average case = 300*0.02 = 6 msec
94
A magnetic disk storage system
Given:
Rotation speed = 7,200 rev/min=120 rev/sec = 8.33 msec/rev
Arm movement time = 0.02 msec to move to an adjacent track
On average, the read/write head must move about 300 tracks
Number of tracks/surface = 1,000
Number of sectors/track = 64
Number of bytes/sector = 1,024
Latency
Best case = 0 msec;
Worst case = 8.33 msec
Average case = 4.17 msec
95
A magnetic disk storage system
Given:
Rotation speed = 7,200 rev/min=120 rev/sec = 8.33
msec/rev
Arm movement time = 0.02 msec to move to an adjacent
track
On average, the read/write head must move about 300
tracks
Number of tracks/surface = 1,000
Number of sectors/track = 64
Number of bytes/sector = 1,024
Transfer time
1/64 * 8.33 msec = 0.13 msec
96
97
98
Magnetic tape storage
99
CD storage
100
Files
File: A unit of data stored in mass storage system
Fields and keyfields
Physical record versus Logical record
Buffer: A memory area used for the temporary storage of
data (usually as a step in transferring the data)
101
Logical records versus physical records
on a disk
102