Binary Numbers contd Addition 1 0 1 1
Binary Numbers (contd) • Addition : 1 0 1 + 1 1 1 _________
Binary 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 = 11
Binary 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 = 11
Binary 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 = 11
Binary 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 = 11
Binary 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 = 11
Binary Numbers (contd) • • Can also do: • Subtraction, Multiplication, etc • Negative Numbers • Fractions Great, but where do Logic Circuits fit in?
Binary Numbers (contd) • And you thought we were done with truth tables • For Addition on small numbers, can make a truth table: X Y Z 0 0 1 1 1 0 1 10 Problem: Output can be 2 bits sometimes
Binary Numbers (contd) • Addition Truth Table with Multiple Outputs: X Y A B 0 0 0 1 1 0
Binary Numbers (contd) • • But we know how to deal with multiple outputs: X Y A X Y B 0 0 0 0 1 1 1 0 0 1 1 1 1 0 Now we can convert into 2 circuits!
Binary Numbers (contd) X Y AND OR AND X Y A 0 0 1 1 1 B X Y B 0 0 1 1 1 0 X Y AND A
Binary Numbers (contd) X Y AND OR AND B X Y B 0 0 1 1 1 0 This is often called the e. Xclusive OR (XOR) circuit We say that B is the exclusive OR of X and Y. We write B = X Y.
A 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.
A 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
Intermission • Questions? ? • How do we actually build a circuit for addition?
Addition X 1 X 2 Y 1 Y 2 ===== C Z 1 Z 2 C is the carry bit X 1 X 2 Y 1 Y 2 Z 1 Z 2 C 0 0 0 0 0 1 0 1 0 0 0 0 1 1 0 0 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 0 0 0 1 1 0 0 1 1 0 1 0 0 1 1 1 1 1 0 1
Addition X 1 X 2 Y 1 Y 2 Z 1 Z 2 C 0 0 0 0 0 1 0 1 0 0 0 0 1 1 0 0 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 0 0 0 1 2 w/ 8 ANDs, 1 OR 1 w/ 6 ANDs, 1 OR 1 0 1 1 1 1 0 0 1 1 0 1 0 0 1 18+7 = 25 gates 1 1 1 0 0 1 1 1 1 0 1 X 2 Y 1 Y 2 ===== C Z 1 Z 2 C is the carry bit Could have 3 circuits (for Z 1, Z 2, C) 16 inputs each
Simplifying the Addition Circuit X 1 X 2 Y 1 Y 2 ===== C Z 1 Z 2 Rewrite as X 2 X 1 Y 2 Y 1 ==== C 2 Z 2 ==== C Z 1
Addition X 2 X 1 Y 1 C 2 C Z 1 Y 1 0 0 0 0 1 ==== C 2 0 1 0 0 1 C 2 Z 2 ==== 0 1 1 1 0 0 0 1 1 0 1 1 1 C Z 1 2 circuits (C 2, Z 2) 2 circuits (C, Z 1) 4 gates 10 gates
Addition X 2 Z 2 Y 2 X 1 Circuit For Z 2 and carry C 2 Z 1 Circuit For Z 1 and carry Carry Y 1 • Can be cascaded for adding longer numbers • We can use 2 building blocks to add numbers of any length.
Adding 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 Y ith bit of Z carry bit out carry bit in Abstraction in action -- This is a piece of a carry-ripple adder
Adding Binary Numbers of Any Length • Write the numbers as – X 4 X 3 X 2 X 1 X 0 – Y 4 Y 3 Y 2 Y 1 Y 0 • Represent the sum as – C Z 4 Z 3 Z 2 Z 1 Z 0
Adding Binary Numbers of Any Length • Write the numbers as – X 4 X 3 X 2 X 1 X 0 – Y 4 Y 3 Y 2 Y 1 Y 0 • Represent the sum as – C Z 4 Z 3 Z 2 Z 1 Z 0 • Start with X 0, Y 0, 0 in, Z 0 and C 0 out • Then X 1, Y 1, C 0 in and Z 1 and C 1 out. • And so on
Adding Binary Numbers of Any Length At the ith stage ith bit of X ith bit of Y Addition ith bit of Z Circuit carry bit out carry bit in Abstraction in action -- This is a piece of a carry-ripple adder
Adding Binary Numbers of Any Length At each stage, take 2 addends and a bit telling whethere 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 carry bit in Sum bit carry bit out
Carry-Ripple Adder X 0 Y 0 Black Box Z 0 Circuit 0 Fixed at 0 C 0 X 1 Y 1 Black Box Circuit Z 1 C 1 X 2 Y 2 Black Box Z 2 Circuit C 2 X 1 X 0 Y 2 Y 1 Y 0 ====== C 2 Z 1 Z 0
What’s inside the box? Xi Yi Cin Black Box Zi Circuit Cout
What’s inside the box? Xi Yi Cin Universal Circuit Zi Cout Abstraction in Action: Use Truth Tables and the Universal Method
Carry 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
Arithmetic Logical Unit (ALU) • This is the part of the CPU that does arithmetic, logical and comparison operations • We’ve 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)
Pause • Questions? ? • Back to representing information
Representing information • How do we represent characters? – How many characters might we want to represent? – What characters might we want to represent?
Representing information • How do we represent characters? – How many characters might we want to represent? – What characters might we want to represent? • • • A-Z and a-z All the keys on my keyboard Maybe use a power of 2? Maybe use an even power of 2? Maybe an even bigger power of 2? 26 52 104 128 256 65536
Representing 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
Unicode • 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)
What do we do in practice? • Problems – Bits represent too little information – too many are needed – Decimal numbers don’t 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
Shorthand: Hexadecimal Binary Dec Hex 0 0 0 8 8 1 0 0 0 1 9 9 1 0 0 1 2 2 0 0 10 A 1 0 3 3 0 0 1 1 11 B 1 0 1 1 4 4 0 1 0 0 12 C 1 1 0 0 5 5 0 1 13 D 1 1 0 1 6 6 0 1 1 0 14 E 1 1 1 0 7 7 0 1 15 F 1 1 Dec Hex 0 Binary
Hexadecimal • We can add hex numbers – 1+1=2, 2+2=4, 4+4=8, 4+8=C, 2+8=A, … • We can combine 2 hexadecimal numbers to make a byte (2 C) • Hex is easier to read than binary – Decimal 22 is 16 in hex (1*161 + 6*160) rather than 10110 in binary • In ASCII – Hex 41 through 5 A represent A to Z – Hex 61 through 7 A represent a to z
Summary • • • 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
Next Time: Memory Now that we can represent it, how do we store it? ?
- Slides: 40