Presentation is loading. Please wait.

Presentation is loading. Please wait.

Addition : 101 +111 _________________ Binary Numbers (contd)

Similar presentations


Presentation on theme: "Addition : 101 +111 _________________ Binary Numbers (contd)"— Presentation transcript:

1 Addition : 101 +111 _________________ Binary Numbers (contd)

2 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 Binary Numbers (contd)

3 Addition – just like usual: 101 +111 _______________ 0 + 0 =0 0 + 1 = 1 1 + 0 = 1 1 + 1 =10 1 + 1 + 1 = 11 Binary Numbers (contd)

4 Addition – just like usual: 1 101 +111 _______________ 0 Binary Numbers (contd) 0 + 0 =0 0 + 1 = 1 1 + 0 = 1 1 + 1 =10 1 + 1 + 1 = 11

5 Addition – just like usual:1 101 +111 _______________0 Binary Numbers (contd) 0 + 0 =0 0 + 1 = 1 1 + 0 = 1 1 + 1 =10 1 + 1 + 1 = 11

6 Addition – just like usual:1 101 +111 _______________ 1100 Binary Numbers (contd) 0 + 0 =0 0 + 1 = 1 1 + 0 = 1 1 + 1 =10 1 + 1 + 1 = 11

7 Can also do: Subtraction, Multiplication, etc Negative Numbers Fractions Great, but where do Logic Circuits fit in? Binary Numbers (contd)

8 And you thought we were done with truth tables X Y Z 00 0 01 1 10 1 11 10 Problem: Output can be 2 bits sometimes Binary Numbers (contd) For Addition on small numbers, can make a truth table:

9 Addition Truth Table with Multiple Outputs: X Y AB 00 01 10 01 11 10 Binary Numbers (contd)

10 But we know how to deal with multiple outputs: Now we can convert into 2 circuits! X Y A 00 0 01 0 10 0 11 1 X Y B 00 0 01 1 10 1 11 0 Binary Numbers (contd)

11 X Y B 00 0 01 1 10 1 11 0 OR B AND X Y X Y A X Y X Y A 00 0 01 0 10 0 11 1 Binary Numbers (contd)

12 X Y B 00 0 01 1 10 1 11 0 OR B AND X Y 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. Binary Numbers (contd)

13 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 Logic Puzzle

14 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 A Simple Breakthrough

15 Intermission Questions?? How do we actually build a circuit for addition?

16 X1X2Y1Y2Z1Z2C 0000000 0001010 0010100 0011110 0100010 0101100 0110110 0111001 1000100 1001110 1010001 1011011 1100110 1101001 1110011 1111101 X1 X2 Y1 Y2 ========= C Z1 Z2 C is the carry bit Addition

17 X1X2Y1Y2Z1Z2C 0000000 0001010 0010100 0011110 0100010 0101100 0110110 0111001 1000100 1001110 1010001 1011011 1100110 1101001 1110011 1111101 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 18+7 = 25 gates Addition

18 X1 X2 Y1 Y2 ========= C Z1 Z2 Rewrite as X2X1 Y2Y1 ====C2 C2 Z2 ======== C Z1 Simplifying the Addition Circuit

19 X2 Y2 ==== C2 Z2 X1 Y1 C2 ==== C Z1 2 circuits (C2, Z2) 4 gates X1Y1C2CZ1 00000 00101 01001 01110 10001 10110 11010 11111 2 circuits (C, Z1) 10 gates Addition

20 Z2 C2 X1 Y1 Circuit For Z1 and carry Circuit For Z2 and carry Z1 Carry X2 Y2 Addition Can be cascaded for adding longer numbers We can use 2 building blocks to add numbers of any length.

21 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 carry bit in ith bit of Z carry bit out Abstraction in action -- This is a piece of a carry-ripple adder

22 Adding 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

23 Adding 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

24 Adding Binary Numbers of Any Length At the ith stage ith bit of X ith bit of Y carry bit in ith bit of Z carry bit out Abstraction in action -- This is a piece of a carry-ripple adder Addition Circuit

25 Adding 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 carry bit in Sum bit carry bit out

26 Carry-Ripple Adder Z0 C0 Black Box Circuit X0 Y0 Z1 C1 Black Box Circuit X1 Y1 Z2 C2 Black Box Circuit X2 Y2 X2 X1 X0 Y2 Y1 Y0 ============ C2 Z2 Z1 Z0 0 Fixed at 0

27 What’s inside the box? Zi Cout Black Box Circuit Xi Yi Cin

28 What’s inside the box? Zi Cout Universal Circuit Xi Yi Cin Abstraction in Action: Use Truth Tables and the Universal Method

29 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

30 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)

31 Pause Questions?? Back to representing information

32 Representing information How do we represent characters? –How many characters might we want to represent? –What characters might we want to represent?

33 Representing 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

34 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

35 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)

36 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

37 0123456701234567 0000000100100011010001010110011100000001001000110100010101100111 89ABCDEF89ABCDEF 1000100110101011110011011110111110001001101010111100110111101111 Shorthand: Hexadecimal 0123456701234567 8 9 10 11 12 13 14 15 DecHexBinary

38 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 (2C) Hex is easier to read than binary –Decimal 22 is 16 in hex (1*16 1 + 6*16 0 ) rather than 10110 in binary In ASCII –Hex 41 through 5A represent A to Z –Hex 61 through 7A represent a to z

39 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

40 Now that we can represent it, how do we store it?? Next Time: Memory


Download ppt "Addition : 101 +111 _________________ Binary Numbers (contd)"

Similar presentations


Ads by Google