Dr. Clincy Professor of CS

Slides:



Advertisements
Similar presentations
Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
Advertisements

ELEC353 S. al Zahir UBC Sign-Magnitude Representation High order bit is sign: 0 = positive (or zero), 1 = negative Low order bits represent the magnitude:
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
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.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
BINARY ARITHMETIC Binary arithmetic is essential in all digital computers and in many other types of digital systems.
CS Binary Representation of Information Detecting Voltage Levels Why not 10 levels? Would be unreliable Not enough difference between states On/Off.
+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic Part 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.
Operations on Bits Arithmetic Operations Logic Operations
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.
1 2.1 Introduction A bit is the most basic unit of information in a computer. –It is a state of “on” or “off” in a digital circuit. –Sometimes these states.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
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.
Negative binary numbers 1 Computer Architectures M.
Negative Integers Unsigned binary representation can not be used to represent negative numbers. With paper and pencil arithmetic, a number is made negative.
ECE DIGITAL LOGIC LECTURE 3: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/19/2016.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
1 CS 151 : Digital Design Chapter 4: Arithmetic Functions and Circuits 4-3 : Binary Subtraction.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
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)
Representing Positive and Negative Numbers
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:
Cosc 2150: Computer Organization
Negative Integers Unsigned binary representation can not be used to represent negative numbers. With paper and pencil arithmetic, a number is made negative.
Dr. Clincy Professor of CS
CHAPTER 9 COMPUTER ARITHMETIC - ALU
Dr. Clincy Professor of CS
Computer Science 210 Computer Organization
Dr. Clincy Professor of CS
Data Representation in Computer Systems
Section 2: Integer & Floating Point Numbers
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
University of Gujrat Department of Computer Science
Addition and Substraction
Dr. Clincy Professor of CS
Dr. Clincy Professor of CS
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Recent from Dr. Dan Lo regarding 12/11/17 Dept Exam
Computer Science 210 Computer Organization
COMPLEMENTS Complements are used in digital computers for simplifying the subtraction operations and for logical manipulation. There are two types of complements.
MIPS ALU.
Data Representation in Computer Systems
Dr. Clincy Professor of CS
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Dr. Clincy Professor of CS
Unit 18: Computational Thinking
How are negative and rational numbers represented on the computer?
CPS120: Introduction to Computer Science
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
Recent from Dr. Dan Lo regarding 12/11/17 Dept Exam
CSC 220: Computer Organization Signed Number Representation
Data Binary Arithmetic.
COMS 361 Computer Organization
Chapter3 Fixed Point Representation
Chapter 1 (Part c) Digital Systems and Binary Numbers
MIPS ALU.
MIPS ALU.
Two’s Complement & Binary Arithmetic
Presentation transcript:

Dr. Clincy Professor of CS CS 3503 - Chapter 2 Dr. Clincy Professor of CS Dr. Clincy

Computers can not SUBTRACT Therefore, need approaches to represent “signed” numbers Dr. Clincy

. Changing only b3 makes +/- Complementing makes +/- B V alues represented Complementing plus 1 makes +/- Sign and b b b b magnitude 1' s complement 2' s complement 3 2 1 1 1 1 + 7 + 7 + 7 1 1 + 6 + 6 + 6 1 1 + 5 + 5 + 5 1 + 4 + 4 + 4 1 1 + 3 + 3 + 3 1 + 2 + 2 + 2 1 + 1 + 1 + 1 + + + 1 - - 7 - 8 1 1 - 1 - 6 - 7 1 1 - 2 - 5 - 6 1 1 1 - 3 - 4 - 5 1 1 - 4 - 3 - 4 1 1 1 - 5 - 2 - 3 1 1 1 - 6 - 1 - 2 1 1 1 1 - 7 - - 1 More used and more efficient . Dr. Clincy

5-bit Binary Number System with SIGN X4, X3, X2, X1, X0 Dr. Clincy

Sign Magnitude Approach Example: Using signed magnitude binary arithmetic, find the sum of 75 and 46. Once we have worked our way through all eight bits, we are done. In this example, we were careful to pick two values whose sum would fit into seven bits. If that is not the case, we have a problem. Dr. Clincy

Sign Magnitude Approach Example: Using signed magnitude binary arithmetic, find the sum of 107 and 46. We see that the carry from the seventh bit overflows and is discarded, giving us the erroneous result: 107 + 46 = 25. Dr. Clincy

Sign Magnitude Approach The signs in signed magnitude representation work just like the signs in pencil and paper arithmetic. Example: Using signed magnitude binary arithmetic, find the sum of - 46 and - 25. Because the signs are the same, all we do is add the numbers and supply the negative sign when we are done. Dr. Clincy

Sign Magnitude Approach Mixed sign addition (or subtraction) is done the same way. Example: Using signed magnitude binary arithmetic, find the sum of 46 and - 25. The sign of the result gets the sign of the number that is larger. Note the “borrows” from the second and sixth bits. SM is good for “representing signed binary” but not so good for mixed sign computation Dr. Clincy

Sign Magnitude Approach Signed magnitude representation is easy for people to understand, but it requires complicated computer hardware. Another disadvantage of signed magnitude is that it allows two different representations for zero: positive zero and negative zero. For these reasons (among others) computers systems employ 1’s and 2’s complement approaches Dr. Clincy

One’s Complement Approach For example, using 8-bit one’s complement representation: + 3 is: 00000011 - 3 is: 11111100 In one’s complement representation, as with signed magnitude, negative values are indicated by a 1 in the high order bit. Complement systems are useful because they eliminate the need for subtraction. Dr. Clincy

One’s Complement Approach With one’s complement addition, the carry bit is “carried around” and added to the sum. Example: Using one’s complement binary arithmetic, find the sum of 48 and -19 We note that 19 in binary is : 00010011, So -19 in one’s complement is: 11101100. Dr. Clincy

One’s Complement - Binary Addition 1010 (neg 5) +0010 (pos 2) 1100 (neg 3) 1101 (neg 2) +0111 (pos 7) 10100 (overflow – add the 1 back) 0101 (pos 5) Recall complement 0011 Dr. Clincy

1’s Complement Dr. Clincy

1’s Complement Dr. Clincy

One’s Complement Approach Although the “end carry around” adds some complexity, one’s complement is simpler to implement than signed magnitude. But it still has the disadvantage of having two different representations for zero: positive zero and negative zero. Two’s complement solves this problem. Dr. Clincy

Two’s Complement Approach To express a value in two’s complement representation: If the number is positive, just convert it to binary and you’re done. If the number is negative, find the one’s complement of the number and then add 1. Example: In 8-bit binary, 3 is: 00000011 -3 using one’s complement representation is: 11111100 Adding 1 gives us -3 in two’s complement form: 11111101. Dr. Clincy

Two’s Complement Approach With two’s complement arithmetic, all we do is add our two binary numbers. Just discard any carries emitting from the high order bit. Example: Using two’s complement binary arithmetic, find the sum of 48 and - 19. We note that 19 in binary is: 00010011, So -19 using one’s complement is: 11101100, So -19 using two’s complement is: 11101101. Dr. Clincy

Two’s Complement Approach Example: Using two’s complement binary arithmetic, find the sum of 107 and 46. We see that the nonzero carry from the seventh bit overflows into the sign bit, giving us the erroneous result: 107 + 46 = -103. Sign-bit: Carry-in of 1 and Carry-out of 0 An overflow into the sign bit does not always mean that we have an error. Rule for detecting signed two’s complement overflow: When the “carry in” and the “carry out” of the sign bit differ, overflow has occurred. If the carry-in to the sign bit equals the carry out of the sign bit, no overflow has occurred.

Two’s Complement Approach Example: Using two’s complement binary arithmetic, find the sum of 23 and -9. We see that there is carry into the sign bit and carry out. The final result is correct: 23 + (-9) = 14. Sign-bit: Carry-in of 1 and Carry-out of 0 Rule for detecting signed two’s complement overflow: When the “carry in” and the “carry out” of the sign bit differ, overflow has occurred. If the carry-out of the sign bit equals the carry-in to the sign bit, no overflow has occurred. Dr. Clincy

One’s & Two’s Complement Relationship For negative numbers, it’s easier to first determine the 1’s complement number, then determine the 2’s complement To go from a negative 1’s Comp to 2’s Comp from a magnitude perspective: 2’s complement is 1 more than the 1’s complement (keeping the bits the same) – clarity: 1 less in value (-19 vs -20) or 1 more in magnitude (19 vs 20) To go from a negative 1’s Comp to 2’s Comp from a bit perspective: 2’s complement is 1 bit added to the 1’s complement (keeping the magnitude or value the same) We note that 19 in binary is: 00010011 So -19 using one’s complement is: 11101100 So -20 using two’s complement is: 11101100 So -19 using one’s complement is: 11101100 So -19 using two’s complement is: 11101101 Dr. Clincy