Title: Introduction%20to%20Computing
1Review Our Friend the Logic Puzzle
- Frank will go to the party if Ed goes
AND Dan does NOT. - Dan will go if Bob does NOT go OR if Carole goes.
- Ed will go to the party if Alice AND Bob go.
- Lets start with the Truth Table instead
2Logic Puzzle Circuit
Alice
Ed
Frank
Bob
Dan
Carole
The full circuit for the Logic Puzzle.
3Logic Puzzle Circuit via Truth Table
A
F
A B C F 0 0 0 0 0 0 1 0 0 1 0 0 0 1
1 0 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 0
B
C
4Universal Method Circuits from Any Truth Table
(another example)
First, make circuitsfor each row in the Truth
Table that hasa 1 in the output.
A B C X 0 0 0 1 0 0 1 0 0 1 0 0 0 1
1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1
5Another Example (contd)
A
A B C X 0 0 0 1 0 0 1 0 0 1 0 0 0 1
1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1
B
C
A
B
C
6Another Example (contd)
A
Finally, combine themwith an OR gate.
B
C
X
- The only way X1 is if at least ONE of the
AND gates outputs a 1. - But each AND gate corresponds to a row
in the Truth Table with a 1 in the output!
A
B
C
7Truth Table with Multiple Outputs
X Y A B 0 0 0 0 0 1 0 1 1 0
0 1 1 1 1 0
8Truth Table with Multiple Outputs
So we can convert into 2 circuits
9Build Circuits using Universal Mtehod
10Build Circuits using Universal Mtehod
X
Y
B
X
Y
X
A
Y
11Cleaning up the Drawing
B
X
Y
A
12Universality
- Same idea works no matter how many input/output
variables. - So for ANY Truth Table we can write down, we can
make a circuit for it using only 3 Logic Gates
AND, OR, NOT - This gives us a very powerful tool !
- Our first technical use of abstraction Make a
circuit for that Truth Table is something we can
abstract and understand.
13Additional Issues
- Some issues to think about on your own
- We know that AND,OR, and NOT together are
universal we can make a circuit for any Truth
Table using just these gates ! What else is
universal? - Surprising answer There is a single gatecalled
NAND which is universal all by itself!
14NAND Gate
X Y Z 0 0 1 0 1 1 1 0 1 1 1
0
Logically, AND followed by NOT If the ANDs
output were a 0, the NANDs will be a 1 And
vice versa
15NOT Gate from NAND Gate
X
Z
Y
X Y Z 0 0 1 0 1 1 1 0 1 1 1
0
Is there a fixed value of Y for which NAND table
reduces to NOT?
16NOT Gate from NAND Gate
X
Z
Fix Y at 1
Y
X
Z
X Y Z 0 0 1 0 1 1 1 0 1 1 1
0
1
X Y Z
0 1 1
1 1 0
Truth Table
Truth Table
17Are We Done?
18Limitations of the Universal Method
- For how large a circuit can we realistically
expect to use the Universal Method? - What do we do for larger circuits?
- How do we simplify them?
- Recall two circuits that both solved our logic
puzzle, one simpler than the other
19Numeracy
- How large do circuits get?
- How large do truth tables get?
20Numeracy (contd)
1-input Truth Table 2 rows
21Numeracy (contd)
1-input Truth Table 2 rows
2-input Truth Table 4 rows
22Numeracy (contd)
3-input Truth Table 8 rows
23Numeracy (contd)
Inputs Rows in truth table
1 2
2 4
3 8
4 ??
5 ??
Arbitrary N ??
24Numeracy (contd)
- Each input can be 0 or 1 2 possibilities.
- So if there are 4 inputs, that is a total of 2
2 2 2 16 possible input values.
25Numeracy (contd)
Inputs Rows in truth table
1 2
2 4
3 8
4 16
5 ??
Arbitrary N ??
26Numeracy (contd)
Inputs Rows in truth table
1 2
2 4
3 8
4 16
5 32
Arbitrary N ??
27Numeracy (contd)
- Each input can be 0 or 1 2 possibilities.
- In general, if there are n inputs, there will be
2 2 2 2 2 2
(n times),
or 2n possible input values.
28Numeracy (contd)
Inputs Rows in truth table
1 2
2 4
3 8
4 16
5 32
Arbitrary N 2N
29Powers of 2
- 2n comes up a lot in Computer Science.
- Numbers to memorize
- 21 2, 22 4, 23 8,
- 24 16, 25 32, 26 64,
- 27 128, 28 256, 29 512,
- 210 1024
30Keep Memorizing ?
210 1,024 220 1,048,576 230 1,073,741,824
240 1,099,511,627,776 250 1,125,899,906,842,6
24 260 1,152,921,504,606,846,976
31Lets Make it Easier
- Some rough numbers
- 210 1,024 ? 1,000 (103)
- 220 1,048,576 ? 1,000,000 (106)
(103)2 - 230 ? 1,000,000,000 (109) (103)3
- 240 ? 1,000,000,000,000 (1012) (103)4
- 250 ? (1015)
- 260 ? (1018 )
32Powers of 2 (contd)
- Some rough numbers
- 210 ? 1,000 (103 ) kilo
- 220 ? 1,000,000 (106 ) mega RAM
- 230 ? 109 giga disk
- 240 ? 1012 tera BIG disk
- 250 ? 1015 peta
- 260 ? 1018 exa knowledge
33Sidebar on Exabytes
- It's taken the entire history of humanity through
1999 to accumulate 12 exabytes of information. By
June 2002, the second dozen exabytes were created - 1 exabytes 50,000 times the library of congress
- Floppy disks to make 1 exabyte would stack 24
million miles high.
34Powers of 2 (contd)
- 16 inputs means Truth Tablehas 216 210 26
1,024 64 ?
64,000 rows - Circuit could have more than 64,000 gates
35Limitations of Universal Method
- What about 100 inputs?
- Is it reasonable to use Universal Method on Truth
Table with 100 inputs?
36Limitations of Universal Method
- What about 100 inputs
- Is it reasonable to use Universal Method on Truth
Table with 100 inputs? - 2100 ? 1030
- Each AND/OR/NOT gate uses at least 1 transistor.
- This is way beyond current technology, in fact .
. .
37Limitations of Universal Method
- State-of-the-art transistors are about 0.1
micrometer (mm) on a side - Lined end-to-end, you could fit10,000,000
transistors in 1 m. (? 3 f.) - In a 1 m. by 1 m. square, you could
fit100,000,000,000,000 transistors - Thats still 999,999,999,999,999,
900,000,000,000,000too few for 100 input Truth
Table !
38How Sad Should We Be?
39Not Very
- Just use many Truth Tables, each having fewer
inputs. - Can make an entire computer using only 16-input
Truth Tables and the Universal Method! - On the other hand, must realize that in some
cases, we need more efficient special purpose
circuits than the UniversalMethod. (We wont
cover these.)
40Our First Abstract Tool
Universal Method Circuits for ANY Truth Table
0s 1s
Universal Method
Computers
We are here
41So What?
- We can build logic circuits for 0s and 1s now
- But why should we?
- Answer Because we canrepresent so many
thingswith 0s and 1s.
42The Meaning of 0 and 1
- In Logic, we thought of 0 and 1 as meaning True
and False. - Now, we remove these connotations.
- Definition a bit (binary digit) is just a single
variable that can take value either 0 or 1.
43Representing Information
- Information in the world comes in manyforms
letters, numbers, pictures, sounds - How can we represent these thingswith 0s and
1s? - Lets start with numbers
44Representing Numbers
- Before computers, in many devices, numbers were
typically represented continuously - e.g. Analog Clocks
- But discrete integers are very important
- How many computers do you own?
45Binary Numbers
- How do we count normally?
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 19,
20, 21 98, 99,
100, 999,
1000, - Suppose we only had two numerals 0 and 1.
- Then how would we count?0, 1,
- 10, 11,
- 100, 101, 110, 111,
- 1000, 1001, 1010 1111,
46Binary Numbers (contd)
47What are binary numbers?
- Base 2 rather than base 10
- Decimal numbers
- We write (1234)10 to represent a decimal number
that has 4 units, 3 tens, 2 hundreds and 1
thousand. - (1234)10 1 x103 2 x102 3 x101 4 x100
48What are binary numbers?
- Base 2 rather than base 10
- Decimal numbers
- We write (1234)10 to represent a decimal number
that has 4 units, 3 tens, 2 hundreds and 1
thousand. - (1234)10 1 x103 2 x102 3 x101 4 x100
- Binary numbers
- We write (1001)2 to represent a binary number
that has 1 unit, 0 2s, 0 4s and 1 8. - (1001)2 1 x23 0 x22 0 x21 1 x20
49Conversion
- If (10)10 is called 10, what do we call (10)2 ?
- Can we convert between binary and decimal?
- (123)10 261 1
- 2230 21 1 (20 )1
- 2315 0 22 21 1 (20 )1
- 26 25 24 23 21 20
- . (1111011)2
- (101101) 2 25 23 22 20 32 8 4 1
45
50From Decimal to Binary Method 1
- 101710 / 2 508 R1 1
- 508 / 2 254 R0 0
- 254 / 2 127 R0 0
- 127 / 2 63 R1 1
- 63 / 2 31 R1 1
- 31 / 2 15 R1 1
- 15 / 2 7 R1 1
- 7 / 2 3 R1 1
- 3 / 2 1 R1 1
- 1 / 2 0 R1 1
- 11111110012 101710
51From Decimal to Binary Method 1
- 101710 - 512 (29) 1
- 505 - 256 (28) 1
- 249 - 128 (27) 1
- 121 - 64 (26) 1
- 57 - 32 (25) 1
- 25 - 16 (24) 1
- 9 - 8 (23) 1
- 1 (22) 0
- 1 (21) 0
- 1 - 1 (20) 1
- 11111110012 101710
52Binary Numbers (contd)
- Addition
-
- 1 0 1
- 1 1 1
- _________________
53Binary Numbers (contd)
- Addition Our basic addition table is really
easy now - 0 0 0
- 0 1 1
- 1 0 1
- 1 1 10
54Binary Numbers (contd)
- Addition just like usual
-
- 1 0 1
- 1 1 1
- _______________
-
0 0 0 0 1 1 1 0 1 1 1 10
55Binary Numbers (contd)
- Addition just like usual
- 1
- 1 0 1
- 1 1 1
- _______________
- 0
0 0 0 0 1 1 1 0 1 1 1 10
56Binary Numbers (contd)
- Addition just like usual
- 1 1
- 1 0 1
- 1 1 1
- _______________
- 0 0
0 0 0 0 1 1 1 0 1 1 1 10
57Binary Numbers (contd)
- Addition just like usual
- 1 1
- 1 0 1
- 1 1 1
- _______________
- 1 1 0 0
0 0 0 0 1 1 1 0 1 1 1 10
58Binary Numbers (contd)
- If (10)10 is called 10, what do we call (10)2 ?
- Can we convert between binary and decimal?
- (123)10 261 1
- 2230 21 1 (20 )1
- 2315 0 22 21 1 (20 )1
- 26 25 24 23 21 20
- . (1111011)2
- (101101) 2 25 23 22 20 32 8 4 1
45
59Binary Numbers (contd)
- Can also do
- Subtraction, Multiplication, etc
- Negative Numbers
- Fractions
- Great, but where do Logic Circuits fit in?
60Binary Numbers (contd)
- And you thought we were done with truth tables
- For Addition on small numbers, can make a truth
table
Problem Output canbe 2 bitssometimes
61Binary Numbers (contd)
- Addition Truth Table with Multiple Outputs
X Y A B 0 0 0 0 0 1 0 1 1 0
0 1 1 1 1 0
62Binary Numbers (contd)
63Binary Numbers (contd)
- Same as 2 Truth Tables
- Now we can convert into 2 circuits!
64Binary Numbers (contd)
X
Y
B
X
Y
X
A
Y
65Binary Numbers (contd)
X
Y
B
X
Y
This is often called the eXclusive OR (XOR)
circuit We say that B is the exclusive OR of X
and Y. We write B X Y.
66A Logic Puzzle
- Bob will go to the party if Ed goes OR
Dan goes. - Dan will go if Xena does NOT go AND
Yanni goes. - Ed will go if Xena goes AND
Yanni does NOT go. - This is addition without the carry
- Bob goes if the XOR of Xena and Yanni go.
67A Simple Breakthrough
- We can represent information by bits.(So we
interpret bits to mean things like numbers.) - Then we re-interpret those bits as Logical
True/False values - Finally we use Universal Method to construct
circuits for operations on information (like
Addition)
68Intermission
- Questions??
- How are we going to build a circuit for addition?
69Addition
X1 X2 Y1 Y2 Z1 Z2 C
0 0 0 0 0 0 0
0 0 0 1 0 1 0
0 0 1 0 1 0 0
0 0 1 1 1 1 0
0 1 0 0 0 1 0
0 1 0 1 1 0 0
0 1 1 0 1 1 0
0 1 1 1 0 0 1
1 0 0 0 1 0 0
1 0 0 1 1 1 0
1 0 1 0 0 0 1
1 0 1 1 0 1 1
1 1 0 0 1 1 0
1 1 0 1 0 0 1
1 1 1 0 0 1 1
1 1 1 1 1 0 1
X1 X2 Y1 Y2 C Z1
Z2 C is the carry bit
70Addition
X1 X2 Y1 Y2 Z1 Z2 C
0 0 0 0 0 0 0
0 0 0 1 0 1 0
0 0 1 0 1 0 0
0 0 1 1 1 1 0
0 1 0 0 0 1 0
0 1 0 1 1 0 0
0 1 1 0 1 1 0
0 1 1 1 0 0 1
1 0 0 0 1 0 0
1 0 0 1 1 1 0
1 0 1 0 0 0 1
1 0 1 1 0 1 1
1 1 0 0 1 1 0
1 1 0 1 0 0 1
1 1 1 0 0 1 1
1 1 1 1 1 0 1
X1 X2 Y1 Y2 C Z1
Z2 C is the carry bit Could have 3 circuits 16
inputs each 2 w/ 8 ANDs, 1 OR 1 w 6 ANDs, 1
OR 25 gates
71Addition
X1 X2 Y1 Y2 C Z1
Z2
Rewrite as X2 X1 Y2 Y1 C2 C2
Z2 C Z1
72Addition
X1 Y1 C2 C Z1
X2 Y2 C2 Z2
X1 Y1 C2 C Z1
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
3 circuits total of 10 gates
2 circuits total of 4 gates
73Addition
X2
Z2
Circuit For Z2 and carry
Y2
C2
Z1
Circuit For Z1 and carry
X1
Carry
Y1
74Adding Binary Numbers of Any Length
We can use 2 building blocks to add numbers of
any length. Actually we need only 1 building
block
ith bit of X
ith bit of Z
ith bit of Y
carry bit out
carry bit
Abstraction in action -- This is a piece of a
carry-ripple adder
75Adding Binary Numbers of Any Length
- Write the numbers as
- X4 X3 X2 X1 X0
- Y4 Y3 Y2 Y1 Y0
- Represent the sum as
- C Z4 Z3 Z2 Z1 Z0
76Adding Binary Numbers of Any Length
- Write the numbers as
- X4 X3 X2 X1 X0
- Y4 Y3 Y2 Y1 Y0
- Represent the sum as
- C Z4 Z3 Z2 Z1 Z0
- Start with X0, Y0, 0 in, Z0 and C0 out
- Then X1,Y1,C0 in and Z1 and C1 out.
- And so on
77Adding Binary Numbers of Any Length
At the ith stage
ith bit of X
Universal Circuit
ith bit of Z
ith bit of Y
carry bit out
carry bit
Abstraction in action -- This is a piece of a
carry-ripple adder
78Adding Binary Numbers of Any Length
At each stage, take 2 addends and a bit telling
whether there is a carry and produce a sum bit
and a bit telling if there is a carry. We can
build a black box to do this
addend
Sum bit
addend
carry bit out
carry bit in
79Carry-Ripple Adder
Z1
Z2
Universal Circuit
X2
Z0
Universal Circuit
X1
Universal Circuit
X0
C2
Y2
Y0
Y1
C1
C0
0
Fixed at 0
X2 X1 X0 Y2 Y1
Y0 C2 Z2 Z1 Z0
80Whats inside the box?
Zi
Universal Circuit
Xi
Yi
Cout
Cin
81Whats inside the box?
Zi
Universal Circuit
Xi
Yi
Cout
Cin
Abstraction in Action Use Truth Tables and the
Universal Method
82Carry ripple adders
- Useful for some applications
- Too slow for other
- Delay while waiting for the carry to ripple
- One solution add larger blocks
- Details in the homework assignment
83Arithmetic Logical Unit (ALU)
- This is the part of the CPU that does arithmetic,
logical and comparison operations - Weve built a piece of the ALU
- With abstraction, we could build the other parts
- Multiplication/subtraction/division
- Comparison
- Then we would write a language to let the user
talk to the ALU (programming)
84Pause
- Questions??
- How to build the other parts of the ALU?
- Use abstraction
- Back to representing information
85Representing information
- How do we represent characters?
- How many characters might we want to represent?
- What characters might we want to represent?
86Representing information
- How do we represent characters?
- How many characters might we want to represent?
- What characters might we want to represent?
- A-Z 26
- A-Z and a-z 52
- All the keys on my keyboard 104
- Maybe a power of 2? 128
- Maybe an even power of 2? 256
- Maybe an even bigger power of 2? 65536
87Representing characters
- ASCII is the American Standard Code for
Information Interchange. It is a 7-bit code. - Many 8-bit codes contain ASCII as their lower
half - The ASCII standard was published by the United
States of America Standards Institute (USASI) in
1968.
88Unicode
- Universal Character Set (UCS) contains all
characters of all other character set
standards. It also guarantees round-trip
compatibility, i.e., conversion tables can be
built such that no information is lost when a
string is converted from any other encoding to
UCS and back. - UCS contains the characters required to
represent almost all known languages. This
includes apart from the many languages which use
extensions of the Latin script also the
following scripts and languages Greek,
Cyrillic, Hebrew, Arabic, Armenian, Gregorian,
Japanese, Chinese, Hiragana, Katakana, Korean,
Hangul, Devangari, Bengali, Gurmukhi, Gujarati,
Oriya, Tamil, Telugu, Kannada, Malayam,
Thai, Lao, Bopomofo, and a number of others. Work
is going on to include further scripts like
Tibetian, Khmer, Runic, Ethiopian, Hieroglyphics,
various Indo-European languages, and many others. - Its intended to use 31 bits (32768 possible
characters)
89What do we do in practice
- Problems
- Bits represent too little too many are needed
- Decimal numbers dont translate well into bits
- So,
- Group into blocks of 4 and 8 bits
- 8 bits 256 characters, holds ASCII
- 8 bits make 1 byte things are organized into
bytes - 4 bits make 1 nibble
90Shorthand Hexadecimal
91Hexadecimal
- We can add numbers
- 112, 224, 448, 48C, 28A,
- We can combine 2 hexadecimal numbers to make a
byte. - Its easier to read than 0s and 1s
- In ASCII
- hex 41 through 5A represent A to Z
- Hex 61 through 7A represent a to z
92Summary
- Reviewed gates and the Universal Method
- Showed that the universal method can lead to very
big circuits - Fixed the problem
- Demonstrated the fix
- Carry-ripple adder
- Represented characters
- Hexadecimal
- Bytes, nibbles
93Next Time Memory
Now that we can represent it, how do we store
it??