ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.

Slides:



Advertisements
Similar presentations
COE 202: Digital Logic Design Signed Numbers
Advertisements

James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Fixed-Point Arithmetics: Part I
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 =
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
ECE 331 – Digital System Design
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
ECE 301 – Digital Electronics Number Systems and Conversion, Binary Arithmetic, and Representation of Negative Numbers (Lecture #10) The slides included.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed 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.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
1.6 Signed Binary Numbers.
Binary Representation - Shortcuts n Negation x + x = 1111…1111 two = -1 (in 2’s complement) Therefore, -x = x + 1 n Sign Extension o Positive numbers :
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
Chapter 7 Arithmetic Operations and Circuits Binary Arithmetic Addition –When the sum exceeds 1, carry a 1 over to the next-more-significant column.
Representing Integer Data Book : Chapter ( Subject has no point !! ) A99ACF.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.
ECE 331 – Digital System Design
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
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.
ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Tech.
Charles Kime & Thomas Kaminski © 2004 Pearson Education, Inc. Terms of Use (Hyperlinks are active in View Show mode) Terms of Use Logic and Computer Design.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
ECE 331 – Digital System Design Representation and Binary Arithmetic of Negative Numbers and Binary Codes (Lecture #10) The slides included herein were.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
Tutorial: ITI1100 Dewan Tanvir Ahmed SITE, UofO
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
Addition and Substraction
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
MIPS ALU. Building from the adder to ALU ALU – Arithmetic Logic Unit, does the major calculations in the computer, including – Add – And – Or – Sub –
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=
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Monday, January 13 CEC 220 Digital Circuit Design Slide 1 of 14.
Introduction * Binary numbers are represented with a separate sign bit along with the magnitude. * For example, in an 8-bit binary number, the MSB is.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Fri, Aug 28 CEC 220 Digital Circuit Design Slide 1 of 14.
IT1004: Data Representation and Organization Negative number representation.
ECE DIGITAL LOGIC LECTURE 3: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/19/2016.
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.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
Integer Operations Computer Organization and Assembly Language: Module 5.
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
Computer Math CPS120 Introduction to Computer Science Lecture 7.
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.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Dr. ClincyLecture 2 Slide 1 CS Chapter 2 (1 of 5) Dr. Clincy Professor of CS Note: Do not study chapter 2’s appendix (the topics will be covered.
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:
Design of Digital Circuits Reading: Binary Numbers
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Wakerly Section 2.4 and further
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Data Representation in Computer Systems
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
ECE 331 – Digital System Design
COMS 361 Computer Organization
Presentation transcript:

ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE

Syllabus Unsigned Binary Overflow Sign Magnitude Radix Complement Two’s Complement Carry and Overflow References

Lecture 2 Topics –Binary Arithmetic, first using unsigned binary operands –Sign number representations Sign Magnitude Diminished Radix Complement (One's complement) Radix Complement (Two's complement) –Binary Arithmetic Revisited and Overflow –Sign Extension 3

Binary Arithmetic Rules for “carry” same as in decimal carry 4

Unsigned Binary (UB) Addition Examples (4-bit word) Overflow >

Overflow (Underflow) Definition of Overflow: Result of an arithmetic operation is too large (or small) to be represented in the number of bits available Detection: Varies with the representation. For unsigned binary, this is determined by a carry out of the MSB bit operands 6

Signed Numbers Have been assuming non-negative numbers –Unsigned Binary (UB) Several representations for signed numbers –Sign Magnitude (SM) –Diminished Radix Complement (DRC) One’s Complement –Radix Complement (RC) Two’s Complement 7

Sign Magnitude MSB functions as sign bit 0 = positive 1 = negative Range of numbers: -(2 n-1 – 1) to +(2 n-1 – 1) n = 6 Two representations for 0 Negative formed by complementing sign bit = SM = SM SM = SM =

Diminished Radix Complement (DRC) Called “One’s Complement” MSB indicates sign 0 = positive 1 = negative Range of numbers: -(2 n-1 – 1) to +(2 n-1 – 1) Two representations for 0 Negative formed by complementing entire word (called “taking the one's complement”) = DRC = DRC DRC = DRC =

Radix Complement (RC) Called “Two’s Complement” MSB indicates sign 0 = positive 1 = negative Range of numbers: -(2 n-1 ) to +(2 n-1 – 1) Only one representation for 0 Negative formed by complementing entire word and adding 1 (called “taking the two's complement”) = RC = RC RC = RC =

Two's complement – Special Cases Example: Take Two's complement (RC) of 0000 (0 10 ) Complement Add One 111 Here ignore carry out of MSB! AKA: Carry-in equals Carry-out! 11

Two's Complement – Special Cases Example: Take Two's complement (RC) of 1000 (-8 10 ) (most negative) Complement Add One 111 Can’t represent abs(most negative number) 12

Conversions of Signed Representations From decimal –Represent the absolute value of the number in UB –Use the correct number of bits (add leading 0s) –If the decimal number is negative, use the appropriate rule to negate the representation S/M – complement the sign bit DRC (one's complement) – complement every bit RC (two's complement) – complement every bit, add 1 To decimal –If number is +, convert from UB to decimal (done!) –If number is - use appropriate rule to negate it (obtain its absolute value) S/M – complement the sign bit DRC (one's complement) – complement every bit RC (two's complement) – complement every bit, add 1 –Convert this (positive) number as though UB to decimal –Add a negative sign 13

Why Use Two's Complement? Only one representation for zero Simplified Addition –Sign Magnitude Addition Must consider two operands without sign bits If sign bits same: perform add, check overflow If sign bits different: subtract (two cases) –+A and – B  A – B –– A and + B  B – A Generate correct sign bit for sum –Radix Complement (Two's Complement) Addition Just add! Simple Subtraction –Done via addition A + B A – B = A + (-B) Caution: Can’t take negative of most negative number 14

Binary Arithmetic Unsigned Binary (UB) Signed Binary (SB) Diminished Radix Complement (DRC) –1s complement Radix Complement (RC) –2s complement Used on CDC Cyber 15

Two's Complement Addition Examples (4-bit word) Ignore carry out of MSB 7 + (-2)5 + (-7) 7 + (-2) 5 + (-7) (-2)

Two's Complement Addition Examples (4-bit word) Carry-into sign bit ≠ Carry-out of sign bit: -7 + (-2) -7 + (-2) We added two negative numbers and got a positive result! Overflow!! 17

Carry and Overflow Is this an overflow condition? If this is an unsigned binary (UB) number – Yes!

Carry and Overflow Is this an overflow condition? If this is a Two’s Complement number – No! A negative number plus a positive number cannot produce Overflow on a Two’s Complement architecture 19

Carry and Overflow Two’s Complement Consider: –Positive + Negative  Never overflow –Negative + Negative  Overflow possible –Positive + Positive  Overflow possible Detecting Overflow: –If signs of addends are same and sign of sum is different –Or easier: If the carry bit into the sign bit differs from the carry bit out of sign bit on a two’s complement architecture, then there is Overflow 20

Carry and Overflow C SBP+1 C SBP C – Carry SBP – Sign Bit Position

Sign Extension What happens when you move a number from a smaller word size to a larger one? (3) (253) UB (3) (-125) S/M (3) (-3) (+253!) RC (2s complement) (-3) “extend” the sign bit left through the new MSB 22