James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.

Slides:



Advertisements
Similar presentations
Computer Engineering (Logic Circuits) Dr. Tamer Samy Gaafar Lec. # 2
Advertisements

©Brooks/Cole, 2003 Chapter 3 Number Representation.
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.
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
Signed Numbers.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Complements: different approaches for representing negative numbers
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.
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.
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.
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
Number Systems Lecture 02.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
School of Computer Science G51CSA 1 Computer Arithmetic.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
1.6 Signed Binary Numbers.
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
The Binary Number System
Data Representation Number Systems.
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Data Representation – Binary Numbers
Computer Arithmetic Nizamettin AYDIN
Representing Integer Data Book : Chapter ( Subject has no point !! ) A99ACF.
James Tam Number systems and logic What is the decimal based number system How does the binary number system work Converting between decimal and binary.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
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.
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.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
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 Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
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.
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.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Binary Arithmetic.
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
Negative binary numbers 1 Computer Architectures M.
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.
Numerical formats What’s the main idea? Want to represent numbers (eg: 45, -12, ) using only bits. We’ve already seen (or you can read in the book)
1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition.
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
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
Binary Arithmetic James A. Rome Tennessee Governor's Academy August 2010.
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 Binary Numbers
Unit 18: Computational Thinking
How are negative and rational numbers represented on the computer?
ECE 331 – Digital System Design
Lecture No.5.
Chapter3 Fixed Point Representation
Two’s Complement & Binary Arithmetic
Presentation transcript:

James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How are subtractions performed by the computer?

James Tam Subtraction In the real world A - B In the computer A - B

James Tam Subtraction In the real world A - B In the computer A - B Not done this way! A + (-B)

James Tam Binary Subtraction Requires the complementing of a binary number -i.e., A – B becomes A + (-B) The complementing can be performed by representing the negative number as a ones or twos complement value.

James Tam Complementing Binary Using The Ones Complement Representation For positive values there is no difference (no change is needed) -e.g., positive seven (The ‘A’ in the expression A – B) 0111 (regular binary) For negative values complement the number by negating the binary values: reversing (flipping) the bits (i.e., a 0 becomes 1 and 1 becomes 0). -e.g., minus six (The ‘B’ in the expression A – B becomes A+(-B)) (regular binary) 0111 (Ones complement equivalent) 1001 (Ones complement equivalent)

James Tam Complementing Binary Using The Twos Complement Representation For positive values there is no difference (no change is needed) -e.g., positive seven (The ‘A’ in the expression A – B) 0111 (regular binary) For negative values complement the number by negating the number: reversing (flipping) the bits (i.e., a 0 becomes 1 and 1 becomes 0) and adding one to the result. -e.g., minus six (The ‘B’ in the expression A – B becomes A+(-B)) (regular binary) 0111 (Twos complement equivalent) 1010 (Twos complement equivalent)

James Tam Interpreting The Bit Pattern: Complements Recall: -Positive values remain unchanged: is the same value with all three representations. -Negative values are converted through complementing: -Ones complement: negate the bits becomes Twos complement: negate the bits and add one becomes 1010 Problem: the sign must be retained (complements don’t use a minus sign). Approach: -One bit (most significant bit/MSB or the signed bit) is used to indicate the sign of the number. -This bit cannot be used to represent the magnitude of the number -If the MSB equals 0, then the 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)

James Tam Summary Of The Three Binary Representations Positive values are represented with: Negative values are represented with: Regular binary No explicit symbol is needed (rarely is a plus ‘+’ used) e.g., 100 vs A minus ‘-’ sign e.g., -100 Ones complement The sign bit (MSB) is zero e.g., 011 The sign bit (MSB) is one e.g., 100 Twos complement The sign bit (MSB) is zero e.g., 011 The sign bit (MSB) is one e.g., 100

James Tam Interpreting The Bits: All Representations Bit patternRegular binaryOnes complementTwos complement

James Tam What You Already Should Know How to convert from decimal to binary. How to convert from binary to decimal.

James Tam What You Will Learn How to subtract numbers with the complement and add technique: The operation A – B is performed as A + (-B)

James Tam Binary Subtraction Via Complement And Add: A High-Level View 1) Convert the decimal values to regular binary 4) Convert the complements to regular binary 2) Convert the regular binary values to complements 5) Convert the regular binary values to decimal 3) Perform the subtraction via complement and add

James Tam Binary Subtraction Via Complement And Add: A High-Level View 1) Convert the decimal values to regular binary 4) Convert the complements to regular binary 2) Convert the regular binary values to complements 5) Convert the regular binary values to decimal 3) Perform the subtraction via complement and add This section

James Tam Reminder: Crossing The Boundary Between Regular And Signed Binary Regular binary Ones complement Twos complement Each time that this boundary is crossed (steps 2 & 4 from the previous slide) apply the rule: 1) Positive numbers pass unchanged 2) Negative numbers must be converted (complemented) a.One’s complement: negate the negative number b.Two’s complement: negate and add one to the result

James Tam Binary Subtraction Through Ones Complements 1)Convert from regular binary to a 1's complement representation (check if it is preceded by a minus sign). a.If the number is not preceded by a minus sign, it’s positive (leave it alone). b.If the number is preceded by a minus sign, the number is negative (complement it by flipping the bits) and remove the minus sign. 2)Add the two binary numbers. 3)Check if there is overflow (a bit is carried out) and if so add it back. 4)Convert the 1’s complement value back to regular binary (check the value of the MSB). a.If the MSB = 0, the number is positive (leave it alone) b.If the MSB = 1, the number is negative (complement it by flipping the bits) and precede the number with a minus sign

James Tam Binary Subtraction Through Ones Complements e.g Step 3: Check for overflow Step 4: Check MSB Step 1: Complement Step 2: Add no.’s Step 4: Leave it alone ______ +1 2 Step 3: Add it back in

James Tam Overflow: Regular Binary Occurs when you don't have enough bits to represent a value (wraps –around to zero) Binary (1 bit) Value Binary (2 bits) Value Binary (3 bits) Value : 00 0 : :

James Tam Overflow: Signed In all cases it occurs do to a “shortage of bits” Subtraction – subtracting two negative numbers results in a positive number. e.g Addition – adding two positive numbers results in a negative number. e.g

James Tam Summary Diagram Of The 3 Binary Representations

James Tam Summary Diagram Of The 3 Binary Representations Overflow

James Tam Binary Subtraction Through Twos Complements 1)Convert from regular binary to a 2's complement representation (check if it’s preceded by a minus sign). a.If the number is not preceded by a minus sign, it’s positive (leave it alone). b.If the number is preceded by a minus sign, the number is negative (complement it and discard the minus sign). i.Flip the bits. ii.Add one to the result. 2)Add the two binary numbers. 3)Check if there is overflow (a bit is carried out) and if so discard it. 4)Convert the 2’s complement value back to regular binary (check the value of the MSB). a.If the MSB = 0, the number is positive (leave it alone). b.If the MSB = 1, the number is negative (complement it and precede the number with a negative sign). i.Flip the bits. ii.Add one to the result.

James Tam Binary Subtraction Through Twos Complements e.g Step 2: Add no’s Step 3: Check for overflow Step 1A: flip bits Step 1B: add

James Tam Binary Subtraction Through Twos Complements e.g Step 1A: flip bits Step 1B: add Step 3: Discard it Step 2: Add no’s

James Tam Binary Subtraction Through Twos Complements e.g Step 1A: flip bits Step 1B: add Step 2: Add no’s Step 4: Check MSB Step 4: Leave it alone

James Tam Representing Real Numbers Via Floating Point Numbers are represented through a sign bit, a mantissa and an exponent Examples with 5 digits used to represent the mantissa: -e.g. One: is represented as * e.g. Two: 0.12 is represented as * e.g. Three: is represented as * 10 1 Sign Mantissa Exponent Using floating point numbers may result in a loss of accuracy!

James Tam You Should Now Know How negative numbers are represented using ones and twos complement representations. How to convert regular binary to values into their ones or twos complement equivalent. What is signed overflow and why does it occur. How to perform binary subtractions via the negate and add technique. How are real numbers represented through floating point representations