Reading Notes #1

advertisement
CHAPTER 1- DATA STORAGE
Section 2
…
…
1.2.2. Binary Addition and Subtraction
Now let's look at the number 110.112 using the same relationship between digit, base, and
position number. Recall the formula for computing the value of a digit:
DIGIT * BASE POSITION #
Since the binary system is a base-2 number system, we can make this formula more specific:
DIGIT * 2 POSITION #
We can analyze the digits of our binary number 110.112 in a table.
Fours
Twos
Ones
2
2
2
1
2
1
1
0
Halves
0
-1
.
Fourths
2
2-2
1
1
Notice that the position values in our table are now powers of two instead of ten. Using our
formula, we see that the first digit of our binary number represents the value 1 * 22 or 4 and the
second digit represents the value 1 * 21 or 2. Continuing this pattern, we can express the number
110.112 as follows:
1*22
1*21
0*20
1*2-1
1*2-2
=
=
=
=
=
1*4
1*2
0*1
1*.5
1*.25
=
=
=
=
=
4.
2.
0.
0.5
+ 0.25
6.75
To find the decimal value of a binary number, we simply calculate the value of each binary digit
and then sum these values.
Now that we understand how to convert between binary and decimal numbers, we are going to
learn how to perform addition and subtraction with binary numbers. For each of these operations,
the technique used to solve the binary problem will parallel the technique you learned to solve
decimal problems. You can verify that your binary answers are correct by converting them back
to decimal.
It is important to note that multiplication and division are really just repeated addition and
repeated subtraction. When we do a multiplication problem like 5 * 3, we are really just
computing the sum of 5 + 5 + 5 which is a repeated addition problem. When we do a division
problem like 15 / 5, we are really just computing the number of times that 5 can be subtracted
from 15. We will return to this idea a little later since it affects the way that computer processors
perform binary arithmetic.
Addition
We need to learn four basic rules in order to perform binary addition. These rules are listed in the
table below. Notice that the first three rules are quite simple since there is no difference between
these binary rules and the corresponding decimal rules. The fourth rule, however, is different
from decimal. Any time that we add two 1s together in binary, we generate a carry to the next
column since the binary system only has two digits. In decimal we have 10 digits, so we do not
generate a carry until the sum of two digits is greater than or equal to 10 (e.g. 5 + 7 = 12).
Rule 1
+
0
0
0
Rule 2
+
0
1
1
Rule 3
+
1
0
1
Rule 4
1
+ 1
10
We can use these rules to derive another important rule for binary arithmetic. Consider what
happens when we try to add three 1s together in binary. Let's split the problem into two addition
problems and apply our rule for binary addition to find the answer.
1. First, we apply Rule 4 to find the sum of the first two 1s.
+
1
1
10
2. Next, we take the previous result of 102 and add the final 1 to it. Notice
that we use Rule 2 (0 + 1 = 1) to find the answer to the first column, and
we use Rule 3 (1 + 0 = 1) to find the answer to the second column.
+
10
1
11
3. Now we have derived another rule for binary arithmetic. The sum of three
1s in binary is 112.
1
1
+ 1
11
It is important to remember that in binary addition, two 1s always generate a carry to the next
column. We can see this happening in the problem above. Adding the first two 1s gives us a carry
to the next column and the remaining 1 becomes the value for the current column.
Subtraction
To do subtraction in the decimal system we normally use the borrow method.
2(10)
Consider the example problem to the right. Here we must borrow a 10 from the tens
3 0
column in order to complete the subtraction in the ones column. We move 10 to the 6
ones column and subtract 6. Then we copy down the remaining 20 from the tens
2 4
column to get our answer of 24.
We can also use the borrow method to do binary subtraction. The basic rules for binary
subtraction are listed in the table below.
Rule 1
-
0
0
Rule 2
-
1
1
Rule 3
-
1
0
Rule 4
-
0
1
0
0
1
1
Again we see that the first three rules are similar to their decimal counterparts. The fourth rule,
however, needs a little more explanation since it defines how we borrow from another column.
Let's look at a simple example to see where this rule comes from. Consider the problem of
subtracting 12 from 102.
1. To compute the first column, we need to borrow a 1 from the next column.
Recall that two 1s generated a carry in addition. If we reverse this process,
we can borrow a 1 from the second column and mark two 1s in the first
column.
2. Once we borrow from the second column, we cross out the 1 and write 0
above it to show this column is now empty. The 1 from the second column is
now represented by the two blue 1s in the first column.
3. To solve our subtraction problem, we take 1 away from our group of two
blue 1s. This leaves us with a single 1 which we write below the first column.
4. After cleaning up our work, we can see that the first column of our answer is
identical to Rule 4. Since we must borrow a 1 from the next column, 0 1 = 1.
-
10
1
1
01
10
- 1
1
01
10
- 1
1
-
10
1
1
Section 3 – Representing information as bit patterns
1.3.2. Representing Real Numbers:
A real number can be uniquely identified by the two components of its scientific notation
(fractional part and the exponent)
123.45 = 12345 x 10-2
.000042 = 42 x 10-6
Thus, any real number can be stored as a pair of integers
 real numbers stored in this format are known as floating point numbers, since the
decimal point moves (floats) to normalize the fraction
Standard formats exist for storing real numbers, using either 32 or 64 bits.
Floating point notation ( 2 byte=16 bit of storage)
Floating point notation ( 1 byte=8 bit of storage)
1.3.3. Representing Characters:
Characters have no natural correspondence to binary numbers
 computer scientists devised an arbitrary system for representing characters as bit
patterns
 ASCII (American Standard Code for Information Interchange)
 maps each character to a specific 8-bit pattern
 note that all digits are contiguous, as are lower- and upper-case letters
'0' < '1' < … < '9'
'A' < 'B' < … < 'Z'
'a' < 'b' < … < 'z'
 Unicode is a 16-bit extension to ASCII that supports other languages
1.3.5. Distinguishing Data Types:
How does a computer know what type of value is stored in a particular piece of memory?
 short answer: it doesn't
 when a program stores data in memory, it must store additional information as to
what type of data the bit pattern represents
 thus, the same bit pattern might represent different values in different contexts
Section 5 – Mass Storage
•
•
•
Typically larger than main memory
Typically less volatile than main memory
Typically slower than main memory
Due to the volatility and limited size of a computer’s main memory, most computers have
additional memory devices called mass storage systems, which include magnetic disks, CDs,
and magnetic tapes.
The advantages of mass storage devices over main memory include less volatility, large storage
capacities, low cost, and in many cases, the ability of removing the unused data.
Magnetic Disks:
Read/Write heads are placed above and/or below the disks so that as the disk spins, each head
traverses a circle, called a track. Since a track can contain more information than we would
normally want to
manipulate at any time, each track is divided into arcs called sectors on which information is
recorded as a continuous strings of bits.
A disk storage system
Each track on a traditional disk contains the same number of sectors, and each sector contains the
same number of bits.
Several measurements are used to evaluate a disk system’s performance:
1. Seek Time: the time required to move read/write heads from one track to
another.
2. Rotation Delay (or Latency Time): half the time required for the disk to
make a complete rotation.
3. Access Time: the sum of seek time and rotation delay.
4. Transfer Rate: the rate at which data can transfer to or from the disk.
The location of tracks and sectors is not a permanent part of a disk’s physical structure. Today’s
31/2 inch floppy disks are capable of holding 1.44 MB of data. Sector sizes are commonly 512
bytes or 1024 bytes (1 KB).
Compact Disc (CD):
Another popular data storage technology is the compact disk (CD). Information on these CDs is
stored on a single track where it is divided into units called sectors, each with its own identifying
markings and a capacity of 2 KB of data.
CD storage system
Magnetic Tape:
An older form of mass storage device uses magnetic tape. The capacity of
these devices depends on the format used, most can hold many gigabytes. A major
disadvantage of it is that moving between different positions on a tape can be very
time-consuming. Information is recorded on the magnetic coating of a thin plastic
tape that is wand on a reel for storage.
A magnetic tape storage mechanism
File Storage and Retrieval:
Information is stored in mass storage systems in large units called files. A typical file way
consists of a complete text document, a photograph, a program, or a collection of data. A file is
simply a string of 1s and 0s that are stored and retrieved as a single unit.
Physical Record: a block of data confirming to the physical characteristics of a
storage device.
Logical Record: blocks of data in physical records called logical records.
Logical Records versus Physical Records
File Names
In MS-DOS or Windows environment, filenames can be up to 8 characters with an optional 3
characters extension.
Windows 95/98 or NT operating systems (environment) allow file-names up to 256 characters.
Types of Files: ASCII to Video
There are many types of files, most of which are defined by the software that created them
(for example , a word processing document or spreadsheet). Popular files are listed here.









ASCII file. An ASCII file is a text-only file that can be read or created by any word
processing program or text editor. (text only) .txt
Data file. A data file contains data organized into records. .dat
Document file. A word processing or desktop publishing document file contains integrated
text and images. .doc
Spreadsheet file. A spreadsheet file contains rows and columns of data. .xls
Source program file. A source program file contains high-level instructions to the computer.
These instructions must be translated to machine language prior to program execution. .pas
, .cpp
Executable program file. An executable program file contains executable machine language
code. .exe
Graphics file. A graphics file contains digitized images. .bmp , .gif , .jpeg
Audio file. An audio file contains digitized sound. .mp3
Video file. A video file contains digitized video frames that when played rapidly(for
example, 30 frames per second) produce motion video. .avi
Download