644
◾
Appendix
• DRAM (main memory): usually 8 gigabytes but as much as 32 gigabytes for desktop
and laptop computers, 1 terabyte or more for mainframe and supercomputers, under
4 gigabytes for handheld devices.
The storage devices consist of hard disk drives, flash drives, optical disks, and magnetic
tape. In order of
smallest to largest capacity, we have the following:
• Flash memory: 1–256 gigabytes, usually in the range of 2–8 gigabytes.
• Optical disk: 750 megabytes up to 8 gigabytes for DVD and up to 128 gigabytes for
Blu Ray.
• Hard disk: internal hard disk drives typically are between 500 gigabytes and 1 tera-
byte, external hard disk drives can have up to 3 terabytes.
• Magnetic tape: up to 5 terabytes.
A.5 BOOLEAN LOGIC
*
The computer operates by applying Boolean operations on bits. The Boolean operators are
AND, OR, NOT, and XOR. We do not typically think at such a low level and instead view
data using more abstract
operations such as addition, multiplication, and comparison. Yet
it is still worth learning the Boolean operators as you will need to understand logic when
writing your own code (see,
for instance, the use of &&, ||, and ! from Chapter 7). You also
need to understand the use of AND to apply a netmask (covered in Chapter 12). So here we
look at these four Boolean operators.
We
apply AND, OR, and XOR on two bits. The NOT operator is applied to a single bit.
Before we go through some examples, let us formally define the four operators.
• AND—outputs 1 if both of the two inputs are 1, otherwise outputs 0.
• OR—outputs 1 if either of the two inputs are 1, otherwise outputs 0.
• XOR—outputs 1 if the two inputs differ, otherwise outputs 0.
• NOT—outputs 1 if the input is 0, otherwise outputs 0. We could also define NOT as
flipping the bit (0 becomes 1, 1 becomes 0).
Table A.8 provides the truth tables for these four operators. The truth table shows all
possible combinations of inputs and their outputs. With two bits, for instance, we might
have 1 OR 0
=
1 or 1 AND 0
=
0. NOT only applies to one bit, for instance, NOT 1
=
0.
As we discussed in Section A.1, having single bit storage is not very useful, so we group
storage cells together. Similarly, performing Boolean operations
on single bits is also not
*
In this section, we omit the subscript 2 after any binary number. Assume all numbers in this section are written in
binary.
Appendix
◾
645
particularly useful. Our Boolean operators are applied pair-wise so that given two binary
values we apply the operator to each corresponding pair of bits of the two numbers. Thus,
we apply AND on the leftmost two bits of the numbers, then the two bits of the next column
and so forth. This is shown in Figure A.1 where we apply AND on the two bytes 00111111
and 01010101.
What follows are the pair-wise application of OR and XOR on the same two binary
numbers.
0 0 1 1 1 1 1 1
0 0 1 1 1 1 1 1
OR
0 1 0 1 0 1 0 1
XOR
0 1 0 1 0 1 0 1
0 1 1 1 1 1 1 1
0 1 1 0 1 0 1 0
The NOT operator only applies on a single binary number. This
operation can be thought
of as flipping each bit (0 becomes 1, 1 becomes 0). For instance, NOT 00111111
=
11000000
and NOT 01011010
=
10100101.
Let us put this into practice. In Chapter 12, we learn about the
netmask
. Given a com-
puter’s IP address and its netmask, we can determine the network address for the computer.
The IP address encapsulates two pieces of information, the computer’s
network address
and the computer’s address within that network. Assume our computer’s IP address is
10.11.12.13. If we have a netmask of 255.255.240.0, we can apply AND to obtain the net-
work’s computer address.
First, we must convert each of these octets from decimal to binary. Then, we apply AND.
The resulting binary number can be converted back to decimal to obtain the network
address.
255.255.240.0
=
11111111.11111111.11110000.00000000
10.11.12.13
=
00001010.00001011.00001100.00001101
ANDing the two numbers
=
00001010.00001011.00000000.00000000
=
10.11.0.0. This
tells us our network address is 10.11.0.0.
TABLE A.8
Truth Table for Boolean Operators
Do'stlaringiz bilan baham: