631
Appendix: Binary and
Boolean Logic
T
his appendix’s learning objectives are
• To understand
the binary numbering system
• To be able to convert numbers between binary and decimal
• To understand the difference between binary, decimal, octal, and hexadecimal
• To understand storage capacities
• To be able to apply Boolean operators and the netmask
A.1 BINARY NUMBERING SYSTEM
Our computers process and store information by means of electrical current flowing
through digital circuits. Although this detail is not something a typical Linux user needs
to know, it does influence a number of aspects of our computer usage.
Most significantly,
current is in one of two states, high current or low (no) current. Our circuits store and pro-
cess information that must be representable in one of two states. For convenience, we refer
to these states as 1 (on) and 0 (off). Thus, what a computer does is store and process binary
information. Binary is the base 2 numbering system.
A numbering system is a means of representing numbers. There are an infinite number
of numbering
systems available to us, but most of our experience is with the decimal (base
10) numbering system. A numbering system of base
k
(where
k
is some integer greater than
0) consists of a range of digits from 0 to
k
−
1 where each digit represents a power of
k
. For
instance, if
k
is 10, then our digits are 0–9 and the digits in a number represent powers of
10 (1, 10, 100, 1000, 10000, and so forth from right to left). The number 362 is really 3 in
the “one hundred’s column,” 6 in the “ten’s column,” and 2 in the “one’s column.” For the
most part, people only use decimal unless they are dealing with computer programming,
computer
networks, computer or electrical engineering, mathematics, or perhaps philoso-
phy of logic. In most of these cases, people may use binary, octal (base 8), or hexadecimal
632
◾
Appendix
(base 16). The reason for octal and hexadecimal usage is that both of these bases allow us
to represent more readable binary values.
Using our definition for base k above, binary (base 2) will consist solely of digits 0 and
1. We refer to a single
b
inary dig
it
as a bit. The digits represent powers of 2.
The powers of
2 are 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, and so forth. These values are computed by
using 2
i
, where i is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, respectively, for the values in the list. If you
do not see the relationship between these numbers, we are multiplying each value by 2 to
get the next one in the sequence, or we are doubling the numbers. The above list represents
the first 11 powers of 2 starting with 2
0
and running through 2
10
.
For the most part, we can
limit our understanding of binary to the first 11 powers of 2 for an interesting reason that
we will consider later. Table A.1 shows the first 11 powers of 2 and the equivalent binary
value as described in this paragraph.
You might notice in the third column of Table A.1 that each successive power of 2 is
represented by adding a 0 at the end. That is, 2 is 10 and 4 is 100, which we got by adding a
0 after 10. We are not really “adding a 0.” Instead, we are
shifting
the number one bit to the
left. A left shift moves all of the digits one bit (location) to the left
and the vacated spot is
filled in with a 0. So, for instance, 10 is 2, left shifting it gives us 10_ and the gap is filled in
with a 0. The left shift then multiplies a number by 2. Similarly, a right shift, which is shift-
ing each bit one position to the right, divides by 2. So, 10000, which is 16, becomes 1000
when
right shifted, or 8.
Using digital circuitry, we construct a “cell” to store a single bit. We need to connect
several cells together to store a meaningful piece of information as a single 0 or 1 does not
tell us much.
The typical size of data storage is measured in either
bytes
or
words
. A byte is 8 bits.
Usually, a computer program is unable to inspect the individual bits in a byte so processes
will look at entire bytes at a time. The byte stores a range of values from 00000000 to
11111111. These represent the decimal numbers 0 to 255, so there are 256 total combina-
tions of 0s and 1s that can be stored in a byte (we confirm this because 2
8
=
256).
TABLE A.1
Powers of 2
Do'stlaringiz bilan baham: