10~chapter_9_part_1

Download Report

Transcript 10~chapter_9_part_1

Exploring engineering
Chapter 9
Logic and Computers
What is “Computation”?
Determining an output by mathematical means

Manual computation
232 + 45*8 + 67/89 = ?

Aids for computation

Automated computation
Historical Roots of the
Computer
Mechanization and automation of
arithmetic
 punch card machinery
 difference and analytical engines
 analog computing devices
Automatic control and logic theory
 automatic control of mechanisms
 development of logic theory
Mechanization of Arithmetic

Abacus (? BC)

Slide Rule - logarithms (1600)

Adding Machines - mechanical (1642)
Punched Card Machinery
Jacquard Loom (1810)
 Cards used to determine
weaving pattern
 hole - no lever pushed
 no hole - lever pushed
 Tied together with ribbons
to provide a sequence of
patterns
Tabulation and Punched
Cards

Herman Hollerith
Tabulating machine
for the 1890 Census

Led to the
development of the
punched card
computer input
Difference and Analytical
Mechanical Computers
Charles Babbage
(early 1800s)
 Difference Engine

Analytical Engine
Analog Computing Devices
Analog - quantities being
computed are direct
proportions of the actual
physical problem.
Analog electronic
computers based on the
operational amplifier, first
constructed with vacuum
tubes
Logic Theory
George Boole,
Augustus DeMorgan
(~1850)

Boolean Algebra - algebra
where variables can take on
only two values
Claude E. Shannon
(1938)

Switching Theory - relates
logic to switch implementation
True
1
False
0
Boolean Logic Theory
 Boole
defined just three operators:
or “intersection” of two statements X
and Y, written X• Y or X * Y - if both true,
then X • Y = 1. If either one is false, then X
•Y=0
 OR or “union” of two statements X and Y,
written X + Y - if either one or both are
true, then X + Y = 1, while only if both are
false is X + Y = 0
 NOT or “negation” X′, of X . Then X′ = 0 if
X = 1, and X′ = 1 if X = 0.
 AND
Boolean Expressions
Boolean variables - can be true or false:
S - the car will start
K - Key is in the car’s ignition
P - the car is in Park
“The car will start if the key is in the ignition and the car is in park.”
output
input
Boolean Expression: S = K · P
input
Boolean Logic Example
 Seat






Belt Warning Light
D is true if any door of the car is open.
PS is true if there is a passenger in the passenger seat.
K is true if the key is in the ignition.
M is true if the motor is running
DB is true if the driver seatbelt is fastened
PB is true if the passenger seatbelt is fastened
"The seatbelt warning light should be on in my car if
W = ____________________________________"
Logic and Binary Numbers
Logic
0 = False 1=True
Binary Number
0 = zero 1 = one
Decimal = Base 10
104 103 102 101 100 . 10-1 10-2 10-3
__ __ __ __ __ . __ __ __
Binary = Base 2
24 23 22 21 20 . 2-1 2-2 2-3
_ _ _ _ _ . _ _ _
The value of a digit depends on its position relative
to the "binary point“ (instead of the “decimal point”).
Decimal Numbers


A “digit” is a place that can hold numerical values
between 0 and 9. Digits are combined together to
create larger numbers. For the number 6,357 the 7 is
in the "1s place," the 5 is in the 10s place, the 3 is in
the 100s place and the 6 is in the 1,000s place. So
you could express it as:
(6 * 1000) + (3 * 100) + (5 * 10) + (7 * 1) = 6000 +
300 + 50 + 7 = 6357
Another way to express it is like this:
(6 * 103) + (3 * 102) + (5 * 101) + (7 * 100) = 6000 +
300 + 50 + 7 = 6357
What you can see from this is that each digit is a
placeholder for the next higher power of 10, starting
in the first digit with 10 raised to the power of zero.
Binary (Base 2) Numbers

Binary Number System
System Digits: 0 and 1
Bit (short for binary digit): A single binary digit
Upper Byte (or nybble): The right-hand byte (or nybble) of a pair
Lower Byte (or nybble): The left-hand byte (or nybble) of a pair

Binary Equivalents
1 Nybble (or nibble) = 4 bits
1 Byte = 2 nybbles = 8 bits
1 Kilobyte (KB) = 1024 bytes
1 Megabyte (MB) = 1024 kilobytes = 1,048,576 bytes
1 Gigabyte (GB) = 1024 megabytes = 1,073,741,824 bytes
Binary (Base 2) Numbers

Computers use binary numbers, and therefore use binary
digits in place of decimal digits. Whereas decimal digits
have 10 possible values ranging from 0 to 9, bits have
only two possible values: 0 and 1.

Therefore, a binary number is composed of only 0s and 1s
like this: 1011.

How do you figure out the decimal value of the binary
number 1011? You do it in the same way we did it for the
decimal number 6357, but you use a base of 2 instead of
a base of 10. For example:
1011 = (1 * 23) + (0 * 22) + (1 * 21) + (1 * 20) = 8 + 0 +
2 + 1 = 11
Binary Counting from 1 to 20
0=0
1=1
2 = 10
3 = 11
4 = 100
5 = 101
6 = 110
7 = 111
8 = 1000
9 = 1001
10 = 1010
11 = 1011
12 = 1100
13 = 1101
14 = 1110
15 = 1111
16 = 10000
17 = 10001
18 = 10010
19 = 10011
20 = 10100
Bits and Bytes

With 8 bits in a byte, you can represent 256
values ranging from 0 to 255, as shown here:
0 = 00000000
1 = 00000001
2 = 00000010
...
254 = 11111110
255 = 11111111
CDs and Bits
 A CD
uses 2 bytes, or 16 bits, per
sample. That gives each sample a
range from 0 to 65,535, like this:
0 = 0000000000000000
1 = 0000000000000001
2 = 0000000000000010
...
65534 = 1111111111111110
65535 = 1111111111111111
CD Data

The total amount of digital data that can be stored on
a CD is:
44,100 samples/channel/second
x 2 bytes/sample
x 2 channels
x 74 minutes
x 60 seconds/minute = 783,216,000 bytes

To fit more than 783 megabytes (MB) onto a disc only
4.8 inches in diameter requires that the individual
bytes be very small. By examining the physical
construction of a CD, you can begin to understand
just how small these bytes are.
How CDs are Made

A CD is a fairly simple piece of plastic, about four onehundredths (4/100) of an inch (1.2 mm) thick. Most of
a CD consists of an injection-molded piece of clear
polycarbonate plastic.

During manufacturing, this plastic is impressed with
microscopic bumps arranged as a single, continuous,
extremely long spiral track of data. We'll return to the
bumps in a moment.

Once the clear piece of polycarbonate is formed, a
thin, reflective aluminum layer is sputtered onto the
disc, covering the bumps.

Then a thin acrylic layer is sprayed over the aluminum
to protect it.
How CDs Work

An infrared laser is focused
onto the metallic reflective
layer of the disc, where a
spiral track of “pits” and
“lands” represents the zeros
and ones of digital signals.
Bits, Bytes, Nybbles, and Words

bit


nybble


Numbers composed of bits
base 10


4 bytes = 32 bits
base 2


8 bits
word


4 bits
byte


A binary digit: 0 or 1
Numbers composed of the digits 0-9
base 16

Numbers composed of the digits 0-9 and letters A-F. Also
called hexadecimal or hex.
The Future of Bytes
Computers are described as having megabytes and
gigabytes of memory. In 64-bit CPU's, memory can be
in terabytes, petabytes, and exabytes.
One kilobyte equals 2 to the 10th power, or
1,024 bytes
One megabyte equals 2 to the 20th power, or
1,048,576 bytes
One gigabyte equals 2 to the 30th power, or
1,073,741,824 bytes
One terabyte equals 2 to the 40th power, or
1,099511,627,776 bytes
One petabyte equals 2 to the 50th power, or
1,125,899,906,842,624 bytes
One exabyte equals 2 to the 60th power, or
1,152,921,504,606,846,976 bytes
One zettabyte equals 2 to the 70th power, or
1,180,591,620,717,411,303,424 bytes
One yottabyte equals 2 to the 80th power, or
1,208,925,819,614,629,174,706,176 bytes
Binary Numbers and Computers

The reason computers use the base 2 system
is because it is easy to implement with simple
electronic “on/off” switching technology.

You could build computers that operate in
base-10, but they would be expensive,
whereas base-2 computers are relatively
cheap.
Binary Addition

Rules of Binary Addition
0+0=0
0+1=1
1+0=1
1 + 1 = 0, and carry 1 to the next more significant bit

Example
1 1
1001101
0011001
----------1100010
1 - Carry bits - 1 1
1001001
0010110
-----------1011101
1000111
0010010
-----------1011111
Rules of Binary Subtraction

Rules of Binary Subtraction
0-0=0
0 - 1 = 1, and borrow 1 from the next more significant bit
1-0=1
1-1=0

Example
* * * *
(starred columns are borrowed from)
1101110
− 10111
---------------1010111
Rules for Binary Multiplication

Rules of Binary Multiplication
0x0=0
0x1=0
1x0=0
1 x 1 = 1, and no carry or borrow bits

Example
101 (decimal 5)
11 (decimal 3)
101
1010
1111 (decimal 5)
More Binary Arithmetic
Addition and Subtraction Examples
(Notice the use of “carry” and “borrow”)
1001 (decimal 9)
+ 101 (decimal 5)
1110 (decimal 14)
1001
- 101
100 (decimal 4)
Using Logic to Describe
Binary Arithmetic
Definition of the variables
for binary addition:
A+B=CS
0+0= 00
0+1= 01
1+0= 01
1+1= 10
Truth table for the
variables C and S
A B C
S
0
0
0
0
0
1
0
1
1
0
0
1
1
1
1
0
Bits to Describe Information
Logic
0 = False
1 = True
Binary Number
00
01
10
11
=
=
=
=
0
1
2
3
Information
00 = “red”
01 = “blue”
10 = “yellow”
11 = “green”
With n bits, we can code 2n different elements
ASCII

American Standard Code for Information
Interchange (ASCII), pronounced ASK-ee, is a
character encoding based on the English alphabet.

ASCII is a seven-bit code, meaning it uses patterns
of seven binary digits (a range of 0 to 127 decimal) to
represent each character.

The first edition of the standard was published in
1963 with 94 printable ASCII characters, numbered
33 to 126 (decimal).
ASCII

ASCII uses a single byte to represent each character. A byte is
a continuous sequence of eight bits (i.e., zeros or ones). This
means that one byte could represent any of 256 characters
(because eight bits allows 256 combinations of zeros and ones)
ranging in binary notation from 0000 0000 to 1111 1111 (the
spaces are added here to simplify reading).

There are 128 standard character encodings in US-ASCII, the
original and most basic version of ASCII. Each of these is a
seven digit binary number between 0000 0000 and 0111 1111.
The eighth (i.e., left-most) bit was originally reserved for use as
a parity bit, i.e., a bit that is used to check the accuracy of the
other bits in the byte.

The first 32 ASCII codes (zero through 31 in decimal notation, or
0000 0000 through 0001 1111 in binary notation) are reserved
for control characters. These are not actually printable
characters; rather, they are codes that were originally intended
to control devices (e.g., printers) that make use of ASCII.
ASCII

For example, Code 0 (0000 0000) represents the null character,
Code 1 (0000 0001) represents the start of a heading, Code 2
(0000 0010) represents the start of text, Code 3 (0000 0011)
represents the end of text, Code 4 (0000 0100) represents the
end of transmission, Code 9 (0000 1001) represents the
horizontal tab key and Code 27 (0001 1011) represents the
escape key.

Code 32 (0010 0000) represents the single space that is
produced by the space bar (located in the center of the bottom
row of a keyboard). Codes 33 through 126 represent the
printable characters, that is, the 52 letters (i.e., 26 upper case
and 26 lower case) of American English as well as the
numerals, punctuation marks and several frequently used
symbols.

Code 127 (0111 1111) is another special character known as
delete. Its original function was to erase a section of paper tape
(a popular storage medium until the 1980s) by punching all
possible holes at a particular character position.
ASCII
Symbol
A
B
C
D
E
F
G
Decimal
65
66
67
68
69
70
71
Binary
01000001
01000010
01000011
01000100
01000101
01000110
01000111
ASCII-Binary Converters
The following web sites have interactive
ASCII-Binary converters:

http://www.theskull.com/javascript/asciibinary.html

http://www.roubaixinteractive.com/PlayGroun
d/Binary_Conversion/Binary_to_Text.asp
What is the use of Boolean and
binary math?
 Modern
computers use these as an
integral part of their design
 The
next section will deal with logic and
computers