Complements: different approaches for representing negative numbers

Slides:



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

COE 202: Digital Logic Design Signed Numbers
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?
James Tam Number Representations You will learn about the binary number system and how subtractions are performed on the computer.
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.
Signed Numbers.
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.
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Two’s Complement 1.As an action: (Assume the starting value is 1011) 1.Flip the bits from the starting value => Add one to get the answer.
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
1.6 Signed Binary Numbers.
Computer Systems 1 Fundamentals of Computing Negative Binary.
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
1 Week 3: Data Representation: Negative Numbers READING: Chapter 3.
1.11, 1.12, 1.13, 1.14, 1.18, 1.20, 1.23, 1.24, 1.25, 1.32, 1.33.
COMPSCI 210 Semester Tutorial 1
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
Complement Numbers. Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude.
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)
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.
Positional Number Systems
Number Representation
ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Tech.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Number Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
Number Systems and Logic Prepared by Dr P Marais (Modified by D Burford)
ECE 331 – Digital System Design Representation and Binary Arithmetic of Negative Numbers and Binary Codes (Lecture #10) The slides included herein were.
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.
Two’s Complement. A system used to represent a negative number in binary A system used to represent a negative number in binary Positive numbers start.
Addition and Substraction
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.
Floating Point Binary A2 Computing OCR Module 2509.
2's Complement Arithmetic
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
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.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Computer Organization 1 Data Representation Negative Integers.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Advanced Binary b. describe and use two’s complement and sign and magnitude to represent negative integers; c. perform integer binary arithmetic, that.
11001 / 101, / ) Perform subtraction on the given unsigned binary numbers using the 2's complement of the subtrahend. Where the result.
Lecture 4: Digital Systems & Binary Numbers (4)
Negative Binary Numbers
11001 / 101 , / ) Perform subtraction on the given unsigned binary numbers using the 2's complement of the subtrahend. Where the.
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Negative Binary Numbers
Addition and Substraction
Unit 18: Computational Thinking
How are negative and rational numbers represented on the computer?
CPS120: Introduction to Computer Science
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
ECE 331 – Digital System Design
Lecture No.5.
Two’s Complement & Binary Arithmetic
Presentation transcript:

Complements: different approaches for representing negative numbers How are negative numbers represented on the computer? Unsigned vs. signed representations One’s and two’s complement representations Performing subtractions via the negate and add approach

Representing negative numbers Real world Positive numbers – just use the appropriate type and number of digits e.g., 12345. Negative numbers – same as the case of positive numbers but precede the number with a negative sign “-” e.g., -123456. Computer world Positive numbers – convert the number to binary e.g., 7 becomes 111 Negative numbers – employ signed representations.

Unsigned binary All of the digits (bits) are used to represent the number e.g. 10102 = 1010 The sign must be represented explicitly (with a minus sign “-”). e.g. –10102 = -1010

Signed binary Positive One bit (called the sign bit or the most significant bit/MSB) is used to indicate the sign of the number If the MSB equals 0 then number is positive e.g. 0 bbb is a positive number (bbb stands for a binary number) If the MSB equals 1 then the number is negative e.g. 1 bbb is a negative number (bbb stands for a binary number) Types of signed binary 1’s complement 2’s complement Negative

Interpreting Unsigned binary and One’s complement Value in decimal 1’s complement 0000 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 -7 1001 9 -6 1010 10 -5 1011 11 -4 1100 12 -3 1101 13 -2 1110 14 -1 1111 15 -0

Converting from unsigned binary to 1’s complement For positive values there is no difference For negative values reverse (flip) the bits (i.e., a 0 becomes 1 and 1 becomes 0). e.g., positive seven 0111 (unsigned) e.g., minus six -0110 (unsigned) 0111 (1’s complement) 1001 (1’s complement)

Interpreting Unsigned binary and Two’s complement Value in decimal 2’s complement 0000 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 -8 1001 9 -7 1010 10 -6 1011 11 -5 1100 12 -4 1101 13 -3 1110 14 -2 1111 15 -1

Converting from unsigned binary to 2’s complement For positive values there is no difference For negative values reverse (flip) the bits (i.e., a 0 becomes 1 and 1 becomes 0) and add one to the result. e.g., positive seven 0111 (unsigned) e.g., minus six -0110 (unsigned) 0111 (2’s complement) 1010 (2’s complement)

Definition of overflow Subtraction – subtracting two negative numbers results in a positive number. e.g. - 7 - 1 + 7 Addition – adding two positive numbers results in a negative number. e.g. 7 + 1 - 8 In both bases it occurs do to a “shortage of bits”

Summary diagram of the 3 binary representations Overflow

Binary subtraction Unsigned binary subtraction e.g., 10002 - 00102 01102 Subtraction via negate and add A - B Becomes A + (-B)

Binary subtraction through 1’s complements Negate any negative numbers (flip the bits) Add the two binary numbers Check if there is overflow (a bit is carried out) and if so add it back. Convert the 1’s complement value back to unsigned binary (check the value of the MSB) If the MSB = 0, the number is positive (leave it alone) If the MSB = 1, the number is negative (flip the bits) and precede the number with a negative sign

Binary subtraction through 1’s complements Step 1: Negate 010002 111012 Step 2: Add no.’s 010002 111012 001012 e.g. 010002 - 000102 Step 3: Add it back in 1 Step 3: Check for overflow ______ +12 Step 4: Check MSB 001102 Leave it alone

Binary subtraction through 2’s complements Negate any negative numbers Flip the bits. Add one to the result. Add the two binary numbers Check if there is overflow (a bit is carried out) and if so discard it. Convert the 2’s complement value back to unsigned binary (check the value of the MSB) If the MSB = 0, the number is positive (leave it alone) If the MSB = 1, the number is negative (flip the bits and add one) and precede the number with a negative sign

Binary subtraction through 2’s complements Step 1A: flip bits 010002 111012 Step 1B: add 1 010002 111102 Step 2: Add no’s 010002 111102 001102 e.g. 010002 - 000102 1 Step 3: Check for overflow Step 4: Check MSB Discard it Leave it alone

Summary (important points) How negative numbers are represented using 1’s and 2’s complements How to convert unsigned values to values into their 1’s or 2’s complement equivalent How to perform binary subtractions via the negate and add technique.