2's Complement Arithmetic

Slides:



Advertisements
Similar presentations
Combinational Circuits. Analysis Diagram Designing Combinational Circuits In general we have to do following steps: 1. Problem description 2. Input/output.
Advertisements

Lab 10 : Arithmetic Systems : Adder System Layout: Slide #2 Slide #3 Slide #4 Slide #5 Arithmetic Overflow: 2’s Complement Conversions: 8 Bit Adder/Subtractor.
EE1A2 Microprocessor Systems & Digital Logic Part I Digital Electronic System Design Dr. T. Collins.
Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.
Computer Engineering (Logic Circuits) Dr. Tamer Samy Gaafar Lec. # 2
Forging new generations of engineers. Binary Addition & Subtraction.
Addition of two binary numbers = = = = 39.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
Complements: different approaches for representing negative numbers
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
The Binary Number System
Data Representation – Binary Numbers
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Arithmetic Nizamettin AYDIN
Conversion Between Lengths Positive number pack with leading zeros +18 = = Negative numbers pack with leading ones -18 =
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
CPS120: Introduction to Computer Science Computer Math: Signed Numbers.
+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic Part 2.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
1 DLD Lecture 18 Recap. 2 Recap °Number System/Inter-conversion, Complements °Boolean Algebra °More Logic Functions: NAND, NOR, XOR °Minimization with.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
Number Systems and Logic Prepared by Dr P Marais (Modified by D Burford)
ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Monday, January 13 CEC 220 Digital Circuit Design Slide 1 of 14.
Outline Binary Addition 2’s complement Binary Subtraction Half Adder
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Fri, Aug 28 CEC 220 Digital Circuit Design Slide 1 of 14.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
Introduction to Digital Electronics Lecture 2: Number Systems.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
Number Representation (Part 2) Computer Architecture (Fall 2006)
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Lecture 4: Digital Systems & Binary Numbers (4)
Chapter 9 Computer Arithmetic
Addition and Subtraction
Negative Binary Numbers
2's Complement Arithmetic
William Stallings Computer Organization and Architecture 7th Edition
Addition and Substraction
Computer Organization and ASSEMBLY LANGUAGE
Complement Theory 1’s and, 2’s complement operation
Complement Theory 1’s and, 2’s complement operation
2’s Complement Arithmetic
ECEG-3202 Computer Architecture and Organization
How are negative and rational numbers represented on the computer?
Chapter 8 Computer Arithmetic
ECE 331 – Digital System Design
Lecture No.5.
2's Complement Arithmetic
Presentation transcript:

2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics 2’s Complement Arithmetic Digital Electronics © 2014 Project Lead The Way, Inc. Project Lead The Way, Inc. Copyright 2009

2’s Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics This presentation will demonstrate The 2’s Complement Process. How the 2’s complement process can be used to add (and subtract) binary numbers. That subtracting one number from another is the same as making one number negative and adding. How to create negative numbers in the binary number system. Introductory Slide / Overview of Presentation Project Lead The Way, Inc. Copyright 2009

Binary Addition Single Bit Addition: Multiple Bit Addition: Carry Cout XOR, XNOR, & Adders Digital Electronics Lesson 2.4 – Specific Comb Circuit & Misc Topics Single Bit Addition: Carry Multiple Bit Addition: Cin Cout A B Sum This slide shows the four possible combinations of adding together two single bit binary numbers and how these single bits can be cascaded into the addition of two 4-bit binary numbers. The 4-bit is just an example; we could have used 8-bits, 12-bits, etc. Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic Negative Numbers? Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics Digital electronics requires frequent addition and subtraction of numbers. You know how to design an adder, but what about a subtract-er? A subtract-er is not needed with the 2’s complement process. The 2’s complement process allows you to easily convert a positive number into its negative equivalent. Since subtracting one number from another is the same as making one number negative and adding, the need for a subtract-er circuit has been eliminated. This slide explains the need to negative number and why we don’t have subtract-er circuits. Project Lead The Way, Inc. Copyright 2009

How To Create A Negative Number 2's Complement Arithmetic How To Create A Negative Number Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics In digital electronics you cannot simply put a minus sign in front of a number to make it negative. You must represent a negative number in a fixed- length binary number system. All signed arithmetic must be performed in a fixed-length number system. A physical fixed-length device (usually memory) contains a fixed number of bits (usually 4-bits, 8- bits, 16-bits) to hold the number. This slide explains why we need a way to represent negative numbers. It introduces the concept of a fixed-length number system. Project Lead The Way, Inc. Copyright 2009

3-Digit Decimal Number System 2's Complement Arithmetic 3-Digit Decimal Number System Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics A bicycle odometer with only three digits is an example of a fixed-length decimal number system. The problem is that without a negative sign, you cannot tell a +998 from a -2 (also a 998). Did you ride forward for 998 miles or backward for 2 miles? Note: Car odometers do not work this way. 999 998 997 001 000 002 forward (+) Before we examine negative binary numbers, let’s first look at something we understand very well: the decimal number system. This slide uses a fixed-length decimal number system to illustrate the limitation of not being able to use a minus sign. backward (-) Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic Negative Decimal 2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics How do we represent negative numbers in this 3- digit decimal number system without using a sign? Cut the number system in half. Use 001 – 499 to indicate positive numbers. Use 500 – 999 to indicate negative numbers. Notice that 000 is not positive or negative. +499 499 498 497 001 000 999 998 501 500 pos(+) +498 +497 +001 000 -001 This slide explains how to represent negative numbers in a fix-length decimal number system. -002 -499 neg(-) -500 Project Lead The Way, Inc. Copyright 2009

“Odometer” Math Examples 2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics 6 + (-3) 3 006 + 997 1003 Disregard Overflow 3 + 2 5 003 + 002 005 (-5) + 2 (-3) 995 + 002 997 (-2) + (-3) (-5) 998 + 997 1995 Disregard Overflow Here are four example of adding two numbers in the odometer number system (i.e., 3-digit decimal number system). It Works! Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic Complex Problems 2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics The previous examples demonstrate that this process works, but how do we easily convert a number into its negative equivalent? In the examples, converting the negative numbers into the 3-digit decimal number system was fairly easy. To convert the (-3), you simply counted backward from 1000 (i.e., 999, 998, 997). This process is not as easy for large numbers (e.g., -214 is 786). How did we determine this? To convert a large negative number, you can use the 10’s Complement Process. Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic 10’s Complement Process Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics The 10’s Complement process uses base-10 (decimal) numbers. Later, when we’re working with base-2 (binary) numbers, you will see that the 2’s Complement process works in the same way. First, complement all of the digits in a number. A digit’s complement is the number you add to the digit to make it equal to the largest digit in the base (i.e., 9 for decimal). The complement of 0 is 9, 1 is 8, 2 is 7, etc. Second, add 1. Without this step, our number system would have two zeroes (+0 & -0), which no number system has. This slide describes the 10’s complement conversion process. Project Lead The Way, Inc. Copyright 2009

10’s Complement Examples 2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics Example #1 -003 Complement Digits  996 Add 1 +1 997 Example #2 Examples of the 10’s Complement Process. -214 Complement Digits  785 Add 1 +1 11 786 Project Lead The Way, Inc. Copyright 2009 11

8-Bit Binary Number System 2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics Apply what you have learned to the binary number systems. How do you represent negative numbers in this 8-bit binary system? Cut the number system in half. Use 00000001 – 01111111 to indicate positive numbers. Use 10000000 – 11111111 to indicate negative numbers. Notice that 00000000 is not positive or negative. +127 01111111 01111110 01111101 00000001 00000000 11111111 11111110 10000001 10000000 pos(+) +126 +125 +1 -1 Introduction to the 8-Bit Binary Number system and how negative numbers are represented. -2 -127 neg(-) -128 Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic Sign Bit 2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics What did do you notice about the most significant bit of the binary numbers? The MSB is (0) for all positive numbers. The MSB is (1) for all negative numbers. The MSB is called the sign bit. In a signed number system, this allows you to instantly determine whether a number is positive or negative. +127 01111111 01111110 01111101 00000001 00000000 11111111 11111110 10000001 10000000 pos(+) +126 +125 +1 -1 Explanation of the sign bit. -2 -127 neg(-) -128 Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic 2’S Complement Process Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics The steps in the 2’s Complement process are similar to the 10’s Complement process. However, you will now use the base two. First, complement all of the digits in a number. A digit’s complement is the number you add to the digit to make it equal to the largest digit in the base (i.e., 1 for binary). In binary language, the complement of 0 is 1, and the complement of 1 is 0. Second, add 1. Without this step, our number system would have two zeroes (+0 & -0), which no number system has. This slide describes the 2’s complement conversion process. Project Lead The Way, Inc. Copyright 2009

2’s Complement Examples 2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics Example #1 5 = 00000101 Complement Digits  11111010 Add 1 +1 -5 = 11111011 Example #2 Examples of the 2’s Complement Process. -13 = 11110011 Complement Digits  00001100 Add 1 +1 13 = 00001101 Project Lead The Way, Inc. Copyright 2009

Using The 2’s Compliment Process 2's Complement Arithmetic Using The 2’s Compliment Process Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics Use the 2’s complement process to add together the following numbers. POS + POS  9 + 5 14 NEG + POS  (-9) + 5 - 4 This slide show that there are only four possible combinations for adding together two signed numbers. The next four slides demonstrate each of these examples. POS + NEG  9 + (-5) 4 NEG + NEG  (-9) + (-5) - 14 Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic POS + POS → POS Answer Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics If no 2’s complement is needed, use regular binary addition. 9 + 5 14  00001001 + 00000101   00001110 Addition of two Positive numbers. Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic POS + NEG → POS Answer Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics Take the 2’s complement of the negative number and use regular binary addition. 9 + (-5) 4  00001001 + 11111011  1]00000100 8th Bit = 0: Answer is Positive Disregard 9th Bit This example shows the addition of one positive and one negative numbers. Note that this is done in the same way as subtracting a positive number from a positive number. In this case, the answer is positive. 00000101  11111010 +1 11111011 2’s Complement Process Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic POS + NEG → NEG Answer 2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics Take the 2’s complement of the negative number and use regular binary addition. (-9) + 5 -4 11110111  + 00000101  11111100 8th Bit = 1: Answer is Negative This slide demonstrates the addition of one positive and one negative number. Again, this is is the same a subtracting a positive number from a positive number. In this case the answer happens to be negative. 11111100  00000011 +1 00000100 To Check: Perform 2’s Complement On Answer 00001001  11110110 +1 11110111 2’s Complement Process Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic NEG + NEG → NEG Answer 2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics Take the 2’s complement of both negative numbers and use regular binary addition. (-9) + (-5) -14  11110111 2’s Complement Numbers, See Conversion Process In Previous Slides 11111011  +  1]11110010 8th Bit = 1: Answer is Negative Disregard 9th Bit This slide demonstrates the addition of two negative numbers. 11110010  00001101 +1 00001110 To Check: Perform 2’s Complement On Answer Project Lead The Way, Inc. Copyright 2009