3 – boolean logic and logic gates 4 – binary...
Post on 15-Mar-2018
235 Views
Preview:
TRANSCRIPT
3 – Boolean Logic and Logic Gates 4 – Binary Numbers
CS 1 Introduction to Computers and Computer Technology
Rick Graziani Fall 2017
Rick Graziani graziani@cabrillo.edu 2
BIT – BInary digiT
• Bit (Binary Digit) = Basic unit of information, representing one of two discrete states. The smallest unit of information within the computer.
• The only thing a computer understands. • Abbreviation: b • Bit has one of two values:
– 0 (off) or 1 (on) – 0 (False) or 1 (True)
OFF ON
Rick Graziani graziani@cabrillo.edu 3
Bits
• Two patterns are known as the state of the bit.
• For example, magnetic encoding of information on tapes, floppy disks, and hard disks are done with positive or negative polarity.
The boxes illustrate a position where magnetism may be set and sensed; pluses (red) indicate magnetism of positive polarity (1 bit), interpreted as “present” and minuses (blue) (0 bit).
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
Rick Graziani graziani@cabrillo.edu 4
Bits
• Bits are really only symbols. • Used to display the one of two different, discrete states. • Bits are used as:
– Storing data • Numbers • Text characters • Images • Sound • Etc.
– Processing data
Rick Graziani graziani@cabrillo.edu 5
Boolean Operations
• Integrated Circuits (microchips) are used to store and manipulate (process) bits.
• This is done using Boolean operations (in honor of mathematician George Boole, 1815-1864).
• Boolean Operation: An operation that manipulates one or more true/false values
• Specific operations – AND – OR – XOR (exclusive or) – NOT
• Using Truth Tables we can uses different sets of logic operations to store, add, subtract, and more complicated operations with bit.
Boolean Algebra and logical expressions (Addendum)
• Boolean algebra (due to George Boole) - The mathematics of digital logic – Useful in dealing with binary system of numbers. – Used in the analysis and synthesis of logical expressions.
• Logical expressions – Expressions constructed using logical-variables and operators. – Result is: True or False
• Boolean algebra – In mathematics a variable uses one of the two possible values: 1 or 0
• May also be represented as: – Truth or Falsehood of a statement – On or Off states of a switch – High (5V) or low (0V) of a voltage level
Rick Graziani graziani@cabrillo.edu 6
Used in electronics (Addendum)
• Electrical circuits are designed to represent logical expressions – Known as logic circuits.
• Used to make important logical decisions in household appliances, computers, communication devices, traffic signals and microprocessors.
• Three basic logic operations as listed below: – OR operation – AND operation – NOT operation
Rick Graziani graziani@cabrillo.edu 7
Logic gates
• A logic gate is an electronic circuit/device which makes the logical decisions based on these operations.
• Logic gates have: – one or more inputs – only one output
• The output is active only for certain input combinations. • Logic gates are the building blocks of any digital circuit.
Rick Graziani graziani@cabrillo.edu 8
Rick Graziani graziani@cabrillo.edu 9
Boolean Operations - AND
• Truth tables (simple ones) • AND operation
– Both input values must be TRUE for output to be TRUE – Kermit is a frog AND Miss Piggy is an actress – Inputs to AND operation represent truth of falseness of the
compound statement.
AND = TRUE
TRUE TRUE
Rick Graziani graziani@cabrillo.edu 10
Boolean Operations
• Gate: – A device that computes a Boolean operation – A device that produces the output of a Boolean operation when
given the operation’s input values. • Gates can be:
– Gears – Relays – Optic devices – Electronic circuits (microchips)
Rick Graziani graziani@cabrillo.edu 11
Boolean Operations – AND Gate
0 = FALSE 1 = TRUE AND operation • Both input values must
be TRUE for output to be TRUE
0
0 0
Truth Table
Inputs Output
0 0
0 1
1 0
1 1
0 0
1 0 0
1
0 0
0
1
1 1
1
Rick Graziani graziani@cabrillo.edu 12
Off (False) On (True)
Off (False)
• To build an AND gate: Two transistors connected together • Two inputs (transistors A and B) and one output • Transistor A: Off (False) • Transistor B: On (True) • Output: Off (False)
Rick Graziani graziani@cabrillo.edu 13
On (True) On (True)
On (True)
• Transistor A: On (True) • Transistor B: On (True) • Output: On (True)
Rick Graziani graziani@cabrillo.edu 14
Boolean Operations - OR
• Truth tables (simple ones) • OR operation
– Only one input values must be TRUE for output to be TRUE – In Rick likes to surf OR Rick likes to go dancing. – Taking both courses will also TRUE.
OR = TRUE TRUE True
Rick Graziani graziani@cabrillo.edu 15
Boolean Operations – OR Gate
0 = FALSE 1 = TRUE OR operation • At least one input value
must be TRUE for output to be TRUE
0
0 0
Truth Table
Inputs Output
0 0
0 1
1 0
1 1
0 0
1 1 1
1
0 1
1
1
1 1
1
Rick Graziani graziani@cabrillo.edu 16
• Two inputs (transistors A and B) and one output • Transistor A: Off (False) • Transistor B: Off (False) • Output: Off (False)
Rick Graziani graziani@cabrillo.edu 17
• Two inputs (transistors A and B) and one output • Transistor A: Off (False) • Transistor B: On (True) • Output: On (True)
Rick Graziani graziani@cabrillo.edu 18
• Two inputs (transistors A and B) and one output • Transistor A: On (True) • Transistor B: On (True) • Output: On (True)
Rick Graziani graziani@cabrillo.edu 19
Boolean Operations - XOR
• Truth tables (simple ones) • XOR operation
– One and ONLY one input value can be TRUE for output to be TRUE
– At noon Rick is going to surf the Hook XOR surf Liquor Stores (this is a surf spot)
– Both cannot be true, as I cannot surf both spots at the same time.
XOR = TRUE TRUE False
Rick Graziani graziani@cabrillo.edu 20
Boolean Operations – XOR Gate
0 = FALSE 1 = TRUE XOR operation • Only one input value is
TRUE for output to be TRUE
Truth Table
Inputs Output
0 0
0 1
1 0
1 1
0
0 0
0 0
1 1 1
1
0 1
1
1
1 0
0
Rick Graziani graziani@cabrillo.edu 21
Rick Graziani graziani@cabrillo.edu 22
Rick Graziani graziani@cabrillo.edu 23
Rick Graziani graziani@cabrillo.edu 24
Boolean Operations – NOT Gate
0 = FALSE 1 = TRUE NOT operation • Only one input • Opposite of input NOT FALSE = TRUE NOT TRUE = FALSE
Truth Table
Inputs Output
0
1
0 1
1
1 0 0
Rick Graziani graziani@cabrillo.edu 25
• To build an NOT gate: One transistor • One input and one output • Transistor A: On (True) • Current flows to ground wire and none
to output, so output is Off (False)
Current
Rick Graziani graziani@cabrillo.edu 26
• Transistor A: Off (False) • Current flows to ground wire and
none to output, so output is Off (False)
Current
http://www.neuroproductions.be/logic-lab/
Rick Graziani graziani@cabrillo.edu 27
Rick Graziani graziani@cabrillo.edu 28
Another way to write it…
0 = FALSE; 1 = TRUE
Binary Numbers
• Binary = Of two states
Rick Graziani graziani@cabrillo.edu 30
Rick Graziani graziani@cabrillo.edu 31
Binary Math
Rick Graziani graziani@cabrillo.edu 32
Base 10 (Decimal) Number System
Digits (10): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Number of: 104 103 102 101 100
10,000’s 1,000’s 100’s 10’s 1’s 1 2 3 9 1 0 9 9 1 0 0
Rick Graziani graziani@cabrillo.edu 33
Base 10 (Decimal) Number System
Digits (10): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Number of: 104 103 102 101 100
10,000’s 1,000’s 100’s 10’s 1’s 4 1 0 8 3 8 2 1 0 0 0 9 1 0 0 1 0
Rick Graziani graziani@cabrillo.edu 34
Rick’s Number System Rules
• All digits start with 0 • A Base-n number system has n number of digits:
– Decimal: Base-10 has 10 digits – Binary: Base-2 has 2 digits – Hexadecimal: Base-16 has 16 digits
• The first column is always the number of 1’s • Each of the following columns is n times the previous
column (n = Base-n) – Base 10: 10,000 1,000 100 10 1 – Base 2: 16 8 4 2 1 – Base 16: 65,536 4,096 256 16 1
Rick Graziani graziani@cabrillo.edu 35
Counting in Decimal (0,1,2,3,4,5,6,7,8,9)
1,000’s 100’s 10’s 1’s 0 1 2 3
... 9
1 0 1 1
... 1 8 1 9 2 0 2 1 2 2
1,000’s 100’s 10’s 1’s . . .
2 9 3 0 3 1
... 9 9
1 0 0 1 0 1
... 9 9 9
1 0 0 0
Rick Graziani graziani@cabrillo.edu 36
Counting in Binary (0, 1)
8’s 4’s 2’s 1’s 0 1
1 0 1 1
1 0 0 1 0 1
8’s 4’s 2’s 1’s
1 1 0
1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
Dec Dec 0 1 2 3 4 5 6
7
8
9
10
11
12
13
14
15
Rick Graziani graziani@cabrillo.edu 37
Binary Math (more later)
0 0 1 10 11 100 101 +0 +1 +1 +1 +1 + 1 + 1 0 1 10 11 100 101 110 111 00000000 11111110 + 1 + 0 -> + 1 1000 …… 00000000 11111111
Rick Graziani graziani@cabrillo.edu 38
Base 2 (Binary) Number System
Digits (2): 0, 1 Number of: 27 26 25 24 23 22 21 20
128’s 64’s 32’s 16’s 8’s 4’s 2’s 1’s Dec. 2 1 0 10 1 0 1 0 17 70 130 255
Rick Graziani graziani@cabrillo.edu 39
Base 2 (Binary) Number System
Digits (2): 0, 1 Number of: 27 26 25 24 23 22 21 20
128’s 64’s 32’s 16’s 8’s 4’s 2’s 1’s Dec. 2 1 0 10 1 0 1 0 17 1 0 0 0 1 70 1 0 0 0 1 1 0 130 1 0 0 0 0 0 1 0 255 1 1 1 1 1 1 1 1
Rick Graziani graziani@cabrillo.edu 40
Converting between Decimal and Binary
Digits (2): 0, 1 Number of: 27 26 25 24 23 22 21 20
128’s 64’s 32’s 16’s 8’s 4’s 2’s 1’s Dec. 1 0 0 0 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 172 192
Rick Graziani graziani@cabrillo.edu 41
Converting between Decimal and Binary
Digits (2): 0, 1 Number of: 27 26 25 24 23 22 21 20
128’s 64’s 32’s 16’s 8’s 4’s 2’s 1’s Dec. 70 1 0 0 0 1 1 0 40 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 128 1 0 0 0 0 0 0 0 172 1 0 1 0 1 1 0 0 192 1 1 0 0 0 0 0 0
Rick Graziani graziani@cabrillo.edu 42
Computers do Binary
0 1 • Bits have two values: OFF and ON • The Binary number system (Base-2) can represent OFF
and ON very well since it has two values, 0 and 1 – 0 = OFF – 1 = ON
• Understanding Binary to Decimal conversion is critical in computer science, computer networking, digital media, etc.
Rick Graziani graziani@cabrillo.edu 43
Rick’s Program
Rick Graziani graziani@cabrillo.edu 44
Rick’s Program
Rick Graziani graziani@cabrillo.edu 45
Rick’s Program
Rick Graziani graziani@cabrillo.edu 46
Decimal Math - Addition
10,000’s 1,000’s 100’s 10’s 1’s
1 6 5 1 0 + 1 6 5 9 5
----------------------------- 50
1
13
1
3
1
Rick Graziani graziani@cabrillo.edu 47
Binary Math - Addition
64’s 32’s 16’s 8’s 4’s 2’s 1’s
1 1 1 0 1 0 + 1 1 0 1 1
----------------------------- 10
1
10
1
1
1
0
1
1
Double check using Decimal.
Dec
58
27 + ----- 85
Rick Graziani graziani@cabrillo.edu 48
Half Adder Gate – Adding two bits
Inputs: A, B S = Sum C = Carry
AND
XOR
A + B = 2’s 1’s
Rick Graziani graziani@cabrillo.edu 49
Half Adder Gate – Adding two bits
Inputs: A, B S = Sum C = Carry
AND
XOR
A + B = 2’s 1’s 0 0 =
0 0
0 0
S C
0
0
0 + 0 ----
0
Rick Graziani graziani@cabrillo.edu 50
Half Adder Gate – Adding two bits
Inputs: A, B S = Sum C = Carry
AND
XOR
A + B = 2’s 1’s 0 1 =
0 1
1 0
S C
1
0
0 + 1 ----
1
Rick Graziani graziani@cabrillo.edu 51
Half Adder Gate – Adding two bits
Inputs: A, B S = Sum C = Carry
AND
XOR
A + B = 2’s 1’s 1 0 =
1 0
1 0
S C
1
0
1 + 0 ----
1
Rick Graziani graziani@cabrillo.edu 52
Half Adder Gate – Adding two bits
Inputs: A, B S = Sum C = Carry
AND
XOR
A + B = 2’s 1’s 1 1 =
1 1
0 1
S C
0
1
1 + 1 ---- 1 0
Rick Graziani graziani@cabrillo.edu 53
Marble Adding Machine
• http://www.youtube.com/watch?v=GcDshWmhF4A&NR=1&feature=fvwp
Rick Graziani graziani@cabrillo.edu 54
Rick Graziani graziani@cabrillo.edu 55
Rick Graziani graziani@cabrillo.edu 56
Text
Rick Graziani graziani@cabrillo.edu 58
Digitizing Text
• Earliest uses of PandA (Presence and Absence) was to digitize text (keyboard characters).
• We will look at digitizing images and video later. • Assigning Symbols in United States:
– 26 upper case letters – 26 lower case letters – 10 numerals – 20 punctuation characters – 10 typical arithmetic characters – 3 non-printable characters (enter, tab, backspace) – 95 symbols needed
Rick Graziani graziani@cabrillo.edu 59
ASCII-7
• In the early days, a 7 bit code was used, with 128 combinations of 0’s and 1’s, enough for a typical keyboard.
• The standard was developed by ASCII (American Standard Code for Information Interchange)
• Each group of 7 bits was mapped to a single keyboard character.
0 = 0000000 1 = 0000001 2 = 0000010 3 = 0000011 … 127 = 1111111
Rick Graziani graziani@cabrillo.edu 60
Byte
Byte = A collection of bits (usually 7 or 8 bits) which represents a character, a number, or other information.
• More common: 8 bits = 1 byte • Abbreviation: B
Rick Graziani graziani@cabrillo.edu 61
Bytes
1 byte (B) Kilobyte (KB) = 1,024 bytes (210) • “one thousand bytes” 1,024 = 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 Megabyte (MB) = 1,048,576 bytes (220) • “one million bytes” Gigabyte (GB) = 1,073,741,824 bytes (230) • “one billion bytes”
Wikipedia
Rick Graziani graziani@cabrillo.edu 62
Rick Graziani graziani@cabrillo.edu 63
ASCII-8
• IBM later extended the standard, using 8 bits per byte.
• This was known as Extended ASCII or ASCII-8
• This gave 256 unique combinations of 0’s and 1’s.
0 = 00000000 1 = 00000001 2 = 00000010 3 = 00000011 … 255 = 11111111
1
Rick Graziani graziani@cabrillo.edu 64
ASCII-8
Rick Graziani graziani@cabrillo.edu 65
Try it!
• Write out Cabrillo College (Upper and Lower case) in bits (binary) using the chart above.
0100 0011 0110 0001 … C a
1
Rick Graziani graziani@cabrillo.edu 66
The answer!
0100 0011 0110 0001 0110 0010 0111 0010 0110 1001 0110 1100 C a b r i l 0110 1100 0110 1111 0010 0000 0100 0011 0110 1111 0110 1100 l o space C o l 0110 1100 0110 0101 0110 0111 0110 0101 l e g e
1
Rick Graziani graziani@cabrillo.edu 67
• Although ASCII works fine for English, many other languages need more than 256 characters, including numbers and punctuation.
• Unicode uses a 16 bit representation, with 65,536 possible symbols. • Unicode can handle all languages. • www.unicode.org
Unicode
3 – Boolean Logic and Logic Gates 4 – Binary Numbers
CS 1 Introduction to Computers and Computer Technology
Rick Graziani
top related