Appendix
◾
641
combinations, 2
1
=
2. This is the smallest unit of storage in a
computer in that we build a
storage device called a memory
cell
capable of storing exactly 1 bit.
As 1 bit cannot store almost anything useful, we group memory cells together to cre-
ate larger storage locations. As we already discussed, 8 bits make up a
byte
. 8 bits give us
2
8
=
256 different combinations for storage. In 1 byte, we can store a number from 0 to 255,
or a number within the range
−
128 to
+
127, or alternatively one of 256
characters using a
character code, or one of 256 different programming instructions.
While the smallest unit of storage is a bit, the smallest
addressable unit
is either a byte or
a word. That is, when the CPU requests something from memory, it is at least the size of a
byte. We therefore use the term byte to describe storage sizes. Over time, computers were
able to move and process more than 1 byte at a time. They began working on 2 or 4
bytes
at a time. The size of the standard datum is known as the
word size
of the computer. Early
computers had 8-bit and 16-bit word sizes. Modern computers have at least 32-bit word
sizes and most today are now 64-bit word sizes (in some cases, there are even 128-bit word
sizes). Many computers today are known as
word addressable
in that they no longer operate
on individual bytes but instead on words.
Let us consider the amount that can be stored in a word of 32 bits. The number of pos-
sible combinations of sequences of 1s and 0s in 32 bits is 2
32
. This is 4,294,967,296
telling us
that a 32-bit word can store any of over 4 billion values! As an integer number, we would be
able to store an unsigned (positive only) number in the range of 0 to 2
32
−
1
=
4,294,967,295
(or if signed number in the range
−
2,147,483,648 to
+
2,147,483,647).
What about storing characters? Recall from the end of Section A.1 that we can store
characters using ASCII or Unicode. The ASCII character set uses 7 bits out of a byte. With
7 bits, we can store any of 2
7
=
128 characters. This is more than enough different combi-
nations of bits to represent the English alphabet (differentiating between uppercase and
lowercase letters) to include the 10 digits, all of the punctuation marks on the keyboard
as well as white space characters (space, tab, enter). There are
many leftover combinations
available to also represent special characters like control characters. If ASCII uses 7 bits of
a byte, what happens to the 8th bit? It is either ignored so that we store the value 0, or we
use it for
parity
. We will discuss parity in Section A.5.
With the worldwide popularity of computers and the Internet, we need to also be able
to represent the characters found in other languages. There is not enough room for this in
ASCII, so Unicode was developed. Unicode stores a character in 16 bits instead of 7. With
16 bits, there are 2
16
=
65,336 combinations of bits, or the ability to store well over 65,000
characters. The first 128 characters of Unicode are the same as the 128 characters of ASCII
so that our textfiles that use ASCII do not have to be altered to be presentable to software
that is using Unicode.
Let us consider a sequence of text such as the following sentence:
The small, brown mouse ran on 4-ever in his cage to catch up with the cheese!
How much storage space would the sentence require? Counting
the number of charac-
ters informs us that there are 58 letters, 1 digit, and 3 punctuation marks. There are also
642
◾
Appendix
15 spaces. Thus, to store the sentence would take 58
+
1
+
3
+
15
=
77 total characters. This
would take 77 bytes in ASCII and 154 bytes in Unicode (because each character is stored
in 2 bytes). If we include the end-of-line characters (often denoted as \n), we have 78 char-
acters requiring 78 bytes (ASCII) or 156 bytes (Unicode).
What about storing thousands or millions of characters? It is useful to extend our
vocabulary of sizes to express these larger capacities. Table A.6 illustrates for several differ-
ent orders of magnitude of storage capacity the amount of text that we can store.
A terabyte of disk storage is readily available today. So we could easily, on our own home
computers, store text equivalent to millions of books. What if the books have pictures?
Image storage is not nearly as concise as text storage. To store an image, we usually use a
representation called a
bitmap
.
The bitmap must encapsulate every point of the image by denoting its color,
or if a black-
and-white image, its shade of gray. Alternatively, we can describe its hue and intensity. We
will call each point a
pixel
(short for picture element). If we assume a single bit for each
pixel, then we can store whether that pixel is on (white) or off (black) to store a simple
black-and-white image. If the image consists of 100 rows and 100 columns, then we need
10,000 bits of storage. In bytes, we divide the bits by 8, or 10,000 bits/8 bits per byte
=
1250
bytes, which is slightly more than 1 kilobyte.
Most images will be larger than 100
×
100,
for instance, 1000
×
1000 instead. We will
also desire color images over black and white. To store a color image, we will represent each
pixel by the amount of red, green, and blue (RGB) that make up that point. RGB storage is
a very common way to represent images. We will use 1 byte to store the amount of each of
the red, green, and blue of the pixel, or 3 bytes per pixel. If we assume a 1000
×
1000
image
using RGB, we would need 3 bytes per pixel*1000*1000 pixels or 3 million bytes, roughly
3 megabytes.
There are compression techniques to reduce the storage size and so rather than storing
raw bitmaps, we use compression to store the file in one of several other formats such as
gif, jpg, or png. These compression techniques can reduce the image file’s size to as little as
about 1/3 its original size. Instead of 3 megabytes, a common image size is around 1 mega-
byte. Notice that 1 megabyte could store 1 million characters, or about 200,000
English
words. Is a picture really worth only a thousand words?
If our average book of 250 pages can be stored as text in 250 kilobytes, what hap-
pens when we insert pictures into the text? Let us assume that each picture is stored in
1 megabyte and that we have a picture on every other page. This gives us 125 images or
TABLE A.6
Equivalent Text for Storage Sizes in Bytes
Do'stlaringiz bilan baham: