Outline Binary Addition 2’s complement Binary Subtraction Half Adder

Slides:



Advertisements
Similar presentations
ADDER, HALF ADDER & FULL ADDER
Advertisements

Combinational Circuits. Analysis Diagram Designing Combinational Circuits In general we have to do following steps: 1. Problem description 2. Input/output.
EET 1131 Unit 7 Arithmetic Operations and Circuits
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.
Number Bases Informatics INFO I101 February 9, 2004 John C. Paolillo, Instructor.
Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
COE 202: Digital Logic Design Signed Numbers
King Fahd University of Petroleum and Minerals
Chapter 4 Operations on Bits
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
ECE 331 – Digital System Design
Binary Operations Math/Logical. Binary Math Decimal Addition Example ) Add = 15 Write down 5, carry ) Add 3 +
IT Systems Number Operations EN230-1 Justin Champion C208 –
FIGURES FOR CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
CS 105 Digital Logic Design
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Dr. Bernard Chen Ph.D. University of Central Arkansas
Binary Addition Addition Rules: = = = = = carry 1 1 carry 1 Example 1: Example 2:
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Simple Data Type Representation and conversion of numbers
A-Level Computing Data representation. Objectives Know how data can be represented in a computer system Understand the need for various forms of representation.
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Today’s Topics How information.
Basic Arithmetic (adding and subtracting)
CS1Q Computer Systems Lecture 9 Simon Gay. Lecture 9CS1Q Computer Systems - Simon Gay2 Addition We want to be able to do arithmetic on computers and therefore.
CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering.
Basic Arithmetic (adding and subtracting)
Calculating Two’s Complement. The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
ECEN 248 Lab 4: Multiplexer Based Arithmetic Logic Unit
Lecture 9 Topics: –Combinational circuits Basic concepts Examples of typical combinational circuits –Half-adder –Full-adder –Ripple-Carry adder –Decoder.
Universal college of engineering & technology. .By Harsh Patel)
Combinational Circuits
Data Representation Bits, Bytes, Binary, Hexadecimal.
Addition and Substraction
Lecture 2 Binary Arithmetic Topics Terminology Fractions Base-r to decimal Unsigned Integers Signed magnitude Two’s complement August 26, 2003 CSCE 211.
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=
CPS3340 Computer Architecture Fall Semester, 2013
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Monday, January 13 CEC 220 Digital Circuit Design Slide 1 of 14.
1. Computing Systems Lecture 3 Binary Representation & Boolean Logic Binary and Logic 2.
Logic Design CS221 1 st Term combinational circuits Cairo University Faculty of Computers and Information.
CEC 220 Digital Circuit Design
2's Complement Arithmetic
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
Number Representation (Part 2) Computer Architecture (Fall 2006)
1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition.
ECE DIGITAL LOGIC LECTURE 15: COMBINATIONAL CIRCUITS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2015, 10/20/2015.
President UniversityErwin SitompulDigital Systems 7/1 Lecture 7 Digital Systems Dr.-Ing. Erwin Sitompul President University
Computing Systems Lecture 3 Binary Representation & Boolean Logic Binary and Logic 1.
Logic Design (CE1111 ) Lecture 4 (Chapter 4) Combinational Logic Prepared by Dr. Lamiaa Elshenawy 1.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Lecture 4: Digital Systems & Binary Numbers (4)
Negative Number Sign-Magnitude: left-most bit as the sign bit –16 bits –Example: 4-bit numbers is given by is given by ’s complement:
Addition and Subtraction
ECE 3130 Digital Electronics and Design
Chapter 4 Operations on Bits.
Digital Systems Section 8 Multiplexers. Digital Systems Section 8 Multiplexers.
Reference: Moris Mano 4th Edition Chapter 4
Addition and Substraction
Number Systems and Circuits for Addition
Digital Systems Section 12 Binary Adders. Digital Systems Section 12 Binary Adders.
Unit 18: Computational Thinking
CPS120: Introduction to Computer Science
ECE 331 – Digital System Design
COMS 361 Computer Organization
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Presentation transcript:

Binary Arithmetic

Outline Binary Addition 2’s complement Binary Subtraction Half Adder Logisim

Binary Addition How to add two binary numbers? Single bit: + 0 + 1 1 1 + 0 1 + 1 10 carry bit

10 13 + 9 2 10 13 + 9 22 13 + 9 Binary Addition What is a carry bit? Same idea as “carry the 1” in decimal arithmetic: 10 13 + 9 2 10 13 + 9 22 13 + 9

Binary Addition carry bit gets “carried over” to the next bit (to the left..) Just like decimal addition + 0 + 1 1 1 + 0 1 + 1 10 carry bit

Binary Addition Example #1 0100 0011 + 0000 1010

Binary Addition Example #1 carry bit 0100 0011 + 0000 1010 0100 1101

0100 0011 + 0000 1010 0100 1101 67 + 10 77 Binary Addition Example #1 You can always check your work by converting to decimal 0100 0011 + 0000 1010 0100 1101 67 + 10 77

Binary Addition Example #2 1100 0110 + 0100 1010

1001 1100 1100 0110 + 0100 1010 1 0001 0000 Binary Addition Example #2 9th bit!?!

1100 0110 + 0100 1010 1 0001 0000 Binary Addition Example #2 If we must store the answer in a single byte, 9th bit gets ignored… This is known as overflow 1100 0110 + 0100 1010 1 0001 0000

Shouldn’t the answer be 272? Binary Addition Example #2 1100 0110 + 0100 1010 1 0001 0000 198 + 74 16 16 !?! Shouldn’t the answer be 272?

Binary Addition What’s the largest number that can be stored in 8-bits? 1111 1111 ???

Binary Addition What’s the largest number that can be stored in 8-bits? 272 is greater than 255 272 cannot be represented using 8 bits Has this ever happened to you? 1111 1111 255

Outline Binary Addition 2’s complement Binary Subtraction Half Adder Logisim

8-bits can be used to represent numbers between 0 and 255 2’s Complement 8-bits can be used to represent numbers between 0 and 255 How do we represent negative numbers in binary? Drumroll…. 2’s complement!! Makes addition, subtraction, multiplication easier Most common way to represent signed numbers Signed: positive AND negative numbers And no, it’s not 2’s compliment “Hey 2, your hair looks nice today..”

In 2’s complement system, the leftmost bit indicates the sign 0 for positive 1 for negative When the leftmost bit is 0, the remaining bits are interpreted as before 0000 0001 => 1 0111 1111 => 127

2’s Complement When the leftmost bit is 1, we do the following to obtain the signed decimal representation: Complement (invert) the binary digits (0 => 1; 1 => 0) Convert binary digits to decimal number Multiply by -1 Subtract 1

1100 0110 Invert bits: 0011 1001 Convert to decimal: 57 2’s Complement Example #1: What is the 2’s complement value of 1100 0110? 1100 0110 Invert bits: 0011 1001 Convert to decimal: 57 Multiple by -1: -57 Subtract 1: -58

2’s Complement Example #2: What is the 2’s complement value of 1001 1001? Your turn! 1001 1001

1001 1001 Invert bits: 0110 0110 Convert to decimal: 102 2’s Complement Example #2: What is the 2’s complement value of 1001 1001? 1001 1001 Invert bits: 0110 0110 Convert to decimal: 102 Multiple by -1: -102 Subtract 1: -103

Decimal to 2’s complement If the number is positive: leftmost bit is 0 remaining bits identical to unsigned binary number E.g., Represent the number 97 using 8-bits, 2’s complement 97 = 64 + 32 + 1 = 26 + 25 + 20 = 0110 0001

Decimal to 2’s complement If decimal number is negative: add 1 multiply by -1 (to create positive number) create binary sequence invert bits

add 1: -97 + 1 = -96 multiply by -1: -96 × -1 = 96 2’s Complement Example #3: represent -97 using 8-bits, 2’s complement add 1: -97 + 1 = -96 multiply by -1: -96 × -1 = 96 get binary: 96 = 0110 0000 invert bits: 1001 1111 -97 => 1001 1111

add 1: -123 + 1 = -122 multiply by -1: -122 × -1 = 122 2’s Complement Example #4: represent -123 using 8-bits, 2’s complement add 1: -123 + 1 = -122 multiply by -1: -122 × -1 = 122 get binary: 122 = 0111 1010 invert bits: 1000 0101 -123 => 1000 0101

Break Time!!!

Outline Binary Addition 2’s complement Binary Subtraction Half Adder Logisim

To subtract two binary numbers, X – Y, Binary Subtraction To subtract two binary numbers, X – Y, Invert Y => Y’ Add 1 to Y’ Add X + Y’ We are basically taking the 2’s complement of Y (Y’) before adding it to X

0010 0001 - 0000 1010 invert Y 00001010 => 11110101 add 1 to Y’ Binary Subtraction Example #5: 0010 0001 - 0000 1010 invert Y 00001010 => 11110101 add 1 to Y’ 11110101 + 00000001 = 11110110 add Y’ to X 0010 0001 + 1111 0110 1 0001 0111 this 9th bit 1 gets ignored

Binary Subtraction It’s always good to verify your work… 0010 0001 0000 1010 0001 0111 33 - 10 23

Binary Subtraction Example #6 0001 1001 1110 0010

Binary Subtraction Example #6 0001 1001 1110 0010 invert Y 1110 0010 => 0001 1101 add 1 to Y’ 0001 1101 + 0000 0001 = 0001 1110 add Y’ to X 0001 1001 + 0001 1110 0011 0111

Binary Subtraction Verify… 0001 1001 1110 0010 0011 0111 25 - -30 55

Outline Binary Addition 2’s complement Binary Subtraction Half Adder Logisim

Can use logic gates to construct adder circuit Half Adder Can use logic gates to construct adder circuit Circuit is capable of binary addition Half Adder has two inputs (A, B) and two outputs (S, C) S: sum C: carry A Half Adder S B C

Truth table for Half Adder S : sum of A + B C : carry bit A B S C 1 Half Adder A B S C

Logic gate circuit for Half Adder? A, B inputs S, C outputs A B S C 1

Logic gate circuit for Half Adder? A, B inputs S, C outputs A B S C 1

How would you expand the Half Adder to create a: 2-bit adder? 4-bit adder? 8-bit adder? …? This will be part of your homework…

Outline Binary Addition 2’s complement Binary Subtraction Half Adder Logisim

Logisim is FREE logic gate simulation software Please download / install this software http://www.cburch.com/logisim/index.html It should be on the lab machines, too

Download / install Logisim Complete homework #2 Next Steps Download / install Logisim Complete homework #2 Data representation Binary arithmetic Create (useful) logic gate circuits using Logisim Next lecture: Micro-architecture