Title: Introduction to Computing
1Binary Numbers (contd)
- Addition
-
- 1 0 1
- 1 1 1
- _________________
2Binary Numbers (contd)
- Addition Our basic addition table is really
easy now - 0 0 0
- 0 1 1
- 1 0 1
- 1 1 10
- What about 1 1 1?
- 1 1 1 11
3Binary Numbers (contd)
- Addition just like usual
-
- 1 0 1
- 1 1 1
- _______________
-
0 0 0 0 1 1 1 0 1 1 1 10 1
1 1 11
4Binary 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 1
1 1 11
5Binary 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 1
1 1 11
6Binary 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 1
1 1 11
7Binary Numbers (contd)
- Can also do
- Subtraction, Multiplication, etc
- Negative Numbers
- Fractions
- Great, but where do Logic Circuits fit in?
8Binary 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
9Binary 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
10Binary Numbers (contd)
- But we know how to deal with multiple outputs
- Now we can convert into 2 circuits!
11Binary Numbers (contd)
X
Y
B
X
Y
X
A
Y
12Binary 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.
13A 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. - Turns out this is addition without the carry
- Bob goes if the XOR of Xena and Yanni go.
14A 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 and construct truth tables for
operations on information (e.g. addition) - Finally we use Universal Method to construct
circuits for these operations
15Intermission
- Questions??
- How do we actually build a circuit for addition?
16Addition
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
17Addition
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 (for
Z1, Z2, C) 16 inputs each 2 w/ 8 ANDs, 1 OR 1 w/
6 ANDs, 1 OR 187 25 gates
18Simplifying the Addition Circuit
X1 X2 Y1 Y2 C Z1
Z2
Rewrite as X2 X1 Y2 Y1 C2 C2
Z2 C Z1
19Addition
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
2 circuits (C, Z1) 10 gates
2 circuits (C2, Z2) 4 gates
20Addition
X2
Z2
Circuit For Z2 and carry
Y2
C2
Z1
Circuit For Z1 and carry
X1
Carry
Y1
- Can be cascaded for adding longer numbers
- We can use 2 building blocks to add numbers of
any length.
21Adding Binary Numbers of Any Length
- Actually we need only 1 building block
- lowest-bit circuit also has 3 inputs, but carry
in is always 0
ith bit of X
ith bit of Z
ith bit of Y
carry bit out
carry bit in
Abstraction in action -- This is a piece of a
carry-ripple adder
22Adding 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
23Adding 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
24Adding Binary Numbers of Any Length
At the ith stage
ith bit of X
Addition Circuit
ith bit of Z
ith bit of Y
carry bit out
carry bit in
Abstraction in action -- This is a piece of a
carry-ripple adder
25Adding Binary Numbers of Any Length
At each stage, take 2 addends and a bit telling
whether there is a carry in, and produce a sum
bit and a bit telling if there is a carry out
We can build a black box to do this
(abstraction)
addend
Sum bit
addend
carry bit out
carry bit in
26Carry-Ripple Adder
Z1
Z2
Black Box Circuit
X2
Z0
Black Box Circuit
X1
Black Box Circuit
X0
C2
Y2
Y0
Y1
C1
C0
0
Fixed at 0
X2 X1 X0 Y2 Y1
Y0 C2 Z2 Z1 Z0
27Whats inside the box?
Zi
Black Box Circuit
Xi
Yi
Cout
Cin
28Whats inside the box?
Zi
Universal Circuit
Xi
Yi
Cout
Cin
Abstraction in Action Use Truth Tables and the
Universal Method
29Carry 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
30Arithmetic Logical Unit (ALU)
- This is the part of the CPU that does arithmetic,
logical and comparison operations - Weve built a piece of the ALU
- Using 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)
31Pause
- Questions??
- Back to representing information
32Representing information
- How do we represent characters?
- How many characters might we want to represent?
- What characters might we want to represent?
33Representing 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 use a power of 2? 128
- Maybe use an even power of 2? 256
- Maybe an even bigger power of 2? 65536
34Representing characters
- ASCII is the American Standard Code for
Information Interchange. It is a 7-bit code. - Many 8-bit codes contain ASCII as the lower half
of their range of values - The ASCII standard was published by the United
States of America Standards Institute (USASI) in
1968 - There are other character coding standards
EBCDIC, and more recently Unicode
35Unicode
- 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. In
addition to the many languages which use
extensions of the Latin script, this also
includes 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. - It uses 31 bits (32768 possible characters)
36What do we do in practice?
- Problems
- Bits represent too little information too many
are needed - Decimal numbers dont translate well into
hardware - 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
- Hexadecimal numbers use 1 nibble per slot or hex
digit - Digits go from 0-9 and then A-F, for 16 possible
values
37Shorthand Hexadecimal
Dec Hex Binary
Dec Hex Binary
8 9 10 11 12 13 14 15
0 1 2 3 4 5 6 7
0 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 0 1 1 1
8 9 A B C D E F
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
0 1 2 3 4 5 6 7
38Hexadecimal
- We can add hex numbers
- 112, 224, 448, 48C, 28A,
- We can combine 2 hexadecimal numbers to make a
byte (2C) - Hex is easier to read than binary
- Decimal 22 is 16 in hex (1161 6160) rather
than 10110 in binary - In ASCII
- Hex 41 through 5A represent A to Z
- Hex 61 through 7A represent a to z
39Summary
- Logic gates and the Universal Method
- Binary representation of numbers and arithmetic
- Universal method can lead to very big circuits
- Solve by reducing to smaller circuits
- Demonstrated with cascading smaller circuits
- Carry-ripple adder
- Represented characters
- Hexadecimal
- Bytes, nibbles
40Next Time Memory
Now that we can represent it, how do we store
it??