Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)

Slides:



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

King Fahd University of Petroleum and Minerals
Wakerly Section 2.4 and further Addition and Subtraction of Nondecimal Numbers.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Signed Numbers.
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.
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.
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.
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.
© 2010 Kettering University, All rights reserved..
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
1.6 Signed Binary Numbers.
Binary numbers and arithmetic. ADDITION Addition (decimal)
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.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
IT253: Computer Organization
Complement Numbers. Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude.
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.
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.
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.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
Sep 29, 2004Subtraction (lvk)1 Negative Numbers and Subtraction The adders we designed can add only non-negative numbers – If we can represent negative.
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.
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
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.
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.
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.
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
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:
Floating Point Numbers Dr. Mohsen NASRI College of Computer and Information Sciences, Majmaah University, Al Majmaah
CS2100 Computer Organisation
Topic: Binary Encoding – Part 2
Cosc 2150: Computer Organization
Design of Digital Circuits Reading: Binary Numbers
Number Systems and Codes (parte 1)
Negative Numbers and Subtraction
Negative Integers Unsigned binary representation can not be used to represent negative numbers. With paper and pencil arithmetic, a number is made negative.
Negative Binary Numbers
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
Section 2: Integer & Floating Point Numbers
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Negative Binary Numbers
CHAPTER 4: Representing Integer Data
Addition and Substraction
CS1010 Programming Methodology
Wakerly Section 2.4 and further
Data Representation in Computer Systems
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Digital Logic & Design Lecture 02.
Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.
EEL 3705 / 3705L Digital Logic Design
Overview Part 1 – Design Procedure Part 2 – Combinational Logic
How are negative and rational numbers represented on the computer?
Number Systems Rayat Shikshan Sanstha’s
Number Systems Rayat Shikshan Sanstha’s
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
ECE 331 – Digital System Design
COMS 361 Computer Organization
Chapter 1 (Part c) Digital Systems and Binary Numbers
Presentation transcript:

Lecture 2 Topics Binary Arithmetic (Unsigned binary operands) Signed number representations Signed Magnitude Diminished Radix Complement (Ones Complement) Radix Complement (Twos Complement) Binary Arithmetic Revisited and Overflow Sign Extension

Binary Arithmetic + 1 + 1 + 1 10 + Rules for “carry” same as in decimal Here are the rules for adding of each bit carry 1 + 1 + 1 + 1 10 + carry

Unsigned Binary (UB) Addition Examples (4-bit word) 2 + 6 11 + 6 0010 0110 + 1 1000 1011 0110 + 1 10001 11 + 6 17 2 + 6 8 Overflow 17 > 24-1

Overflow (Underflow) 10101101 01101100 + 100011001 1 1 1 1 1 Definition: Result of an arithmetic operation is too large (or small) to be represented in number of bits available Detection: Varies with the representation. For unsigned binary, it’s determined by a carry out of the MSB 1 1 1 1 1 10101101 01101100 8 bit operands + 100011001

Signed Numbers Have been assuming non-negative numbers Unsigned Binary (UB) Several representations for signed numbers Sign Magnitude (SM) Diminished Radix Complement (DRC) 1s Complement Radix Complement (RC) 2s Complement

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

Diminished Radix Complement (DRC) Called “Ones Complement” MSB indicates sign 0 = positive 1 = negative (but not a sign bit!) Range of numbers: -(2n-1 – 1) to +(2n-1 – 1) Two representations for 0 Negative formed by complementing entire word (called “taking the ones complement”) 1510 = 001111DRC -1510 = 110000DRC 010100DRC = 2010 101011DRC = -2010

Radix Complement (RC) Called “Twos Complement” MSB indicates sign 0 = positive 1 = negative (but not a sign bit) Range of numbers: -(2n-1) to +(2n-1 – 1) Only one representation for 0 Negative formed by complementing entire word and adding 1 (called “taking the twos complement”) 1510 = 001111RC -1510 = 110001RC 010100RC = 2010 101100RC = -2010

Radix Complement (RC) 000011 =3 111100 = neg 111101=-3 Called “Twos Complement” MSB indicates sign 0 = positive 1 = negative (but not a sign bit) Range of numbers: -(2n-1) to +(2n-1 – 1) Only one representation for 0 Negative formed by complementing entire word and adding 1 (called “taking the twos complement”) 1510 = 001111RC -1510 = 110001RC 010100RC = 2010 101100RC = -2010 1 1 1 1 0 1 -3 000011 =3 111100 = neg 111101=-3

Twos Complement – Special Cases Note: Discard carry out of sign bit position!

Twos Complement – Special Cases Example: Take Twos Complement (RC) of 0000 (010) 0000 1111 + 1 1 1 1 Only one representation for 0 Complement Add One Ignore carry out of MSB Note: Discard carry out of sign bit position!

Twos Complement – Special Cases Example: Take Twos Complement (RC) of 1000 (-810) (most negative) -810 1000 0111 + 1 1 1 1 +810 is not represented Complement Note: Discard carry out of sign bit position! Add One Can’t represent Complement of the most negative number 1000 (-810) is the most negative number

Why do we use RC (Twos Complement)? Only one representation for zero Simplified Addition in Twos Complement! Sign Magnitude Addition has complicated algorithm below: 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 (Twos Complement) Addition Just add! Simple Subtraction Done via addition A + B A – B = A + (-B) Caution: Can’t take negative of most negative number BCD (which we’ll see shortly) was used in very early 4-bit microprocessors, but 2s complement is universally used now

Conversions of Signed Representations

Conversions of Signed Representations From Decimal Conversion from decimal Represent the absolute value of the number in unsigned binary (UB) Use the correct number of bits (add leading 0s) If the decimal number is negative, use the appropriate rule to negate the representation Sing/Magnitude (S/M) – complement the sign bit DRC (ones complement) – complement every bit RC (twos complement) – complement every bit, add 1

Conversions of Signed Representations to Decimal Conversion to decimal if number is + convert from unsigned binary to decimal (done!) Conversion to decimal if number is - use appropriate rule to negate it (obtain its absolute value) Sign/Magnitude – complement the sign bit Ones complement – complement every bit Twos complement – complement every bit, add 1 Convert this (positive) number as though unsigned binary to decimal Add a negative sign

Binary Arithmetic Unsigned Binary (UB) Signed Binary (SB) Diminished Radix Complement (DRC) 1s complement Radix Complement (RC) 2s complement Rarely used

Radix Complement (RC) or Twos Complement Addition – Subtraction and Negative Numbers Examples (4-bit word) 7 + (-2) 5 + (-7) 0101 1001 + 1 1110 0111 1110 + 1 10101 5 + (-7) (-2) 7 + (-2) 5 Ignore carry out of MSB No overflow

Radix Complement (RC) or Twos Complement Addition Examples (4-bit word) -7 + (-2) We added two negative numbers and got a positive result! 1001 1110 + 10111 1 -7 + (-2) -9 Overflow!! -9 < - (23) Ignore carry out of MSB

Carry and Overflow

Carry and Overflow Is this an overflow condition? 10101101 01101100 + 1 100011001 If this is an unsigned binary (UB) number – Yes! Overflow in UB

Carry and Overflow Is this an overflow condition? 10101101 01101100 + 1 100011001 If this is a radix complement (RC) number – No! A negative number plus a positive number cannot produce an overflow No overflow in Twos Complement

Carry and Overflow Radix Complement (2s 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 Equivalent to CSBP ¹ CSBP+1 C – Carry SBP – Sign Bit Position

Carry and Overflow in Twos Complement CSBP = CSBP+1 CSBP+1 CSBP C – Carry SBP – Sign Bit Position 1 1 1 1 1 10101101 01101100 + 100011001 No overflow in Twos Complement A negative number plus a positive number cannot produce an overflow

Addition in Twos Complement Examples (4-bit word) CSBP+1 ¹ CSBP -7 + (-2) We added two negative numbers and got a positive result! CSBP+1 CSBP 1 1001 1110 -7 + (-2) -9 + 10111 Overflow! Returning to our previous example… -9 < - (23) Conclusion on Overflow in 2s Complement: There is an overflow if signs of addends are same and sign of sum is different Equivalent to CSBP ¹ CSBP+1 In this case there is an overflow

Sign Extension What happens when you move a number from a smaller word size to a larger one? UB S/M RC (2s complement) 00000011 0000000000000011 (3) 00000011 0000000000000011 (3) 00000011 0000000000000011 (3) 11111101 0000000011111101 (253) 11111101 1000000001111101 (-125) 11111101 0000000011111101 (-3) (+253!) bad Unsigned Binary is no problem, fill with zeros Sign Magnitude is no problem, sign goes to MSB 11111101 1111111111111101 (-3) good “extend” the sign bit left through the new MSB 26

Subtraction in Two’s -Complement

Addition versus Subtraction Use same technique as decimal Except that the addition and subtraction tables are different Already seen addition table Truth table for Sum and Cout function

Subtraction table difference bin x y bout d 1

Another method of doing subtraction borrow out borrow difference

Examples of decimal and corresponding binary subtractions

A modular counting representation of 4-bit two’s-complement numbers There is no plus 8

A modular counting representation of 4-bit unsigned numbers

Summary of addition and subtraction rules for binary numbers

Questions, Problems and EXAM Problems Meaning of carry bit. Addition of unsigned numbers Addition in two’s-complement system Addition in ones-complement system. Subtraction of unsigned numbers Subtraction in two’s-complement system Subtraction in ones-complement system. Advantages of sign-magnitude system. Advantages of two’s-complement system Advantages of ones-complement system

Questions and problems Questions, Problems and EXAM Problems Questions and problems 11. Discuss examples to add binary numbers in Two’s-complement code (representation) and when it leads to overflow? 12. What are the advantages of Two’s-complement code? 13. Discuss overflow in Two’s-complement code. 14. Discuss subtraction overflow in Two’s-complement code. 15. Discuss advantages and disadvantages of number systems. 16. Discuss sign extension and show examples.

Prof. Mark G. Faust John Wakerly Sources Prof. Mark G. Faust John Wakerly