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

Slides:



Advertisements
Similar presentations
Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
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? How.
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.
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)
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.
Number Representation Rizwan Rehman, CCS, DU. Convert a number from decimal to binary notation and vice versa. Understand the different representations.
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.
School of Computer Science G51CSA 1 Computer Arithmetic.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Binary Representation and Computer Arithmetic
Computer Systems 1 Fundamentals of Computing Negative Binary.
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
The Binary Number System
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Simple Data Type Representation and conversion of numbers
Data Representation – Binary Numbers
Computer Arithmetic Nizamettin AYDIN
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.
1 Digital Technology and Computer Fundamentals Chapter 1 Data Representation and Numbering Systems.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Computer Architecture
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.
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.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Chapter 3 Number Representation. Convert a number from decimal to binary notation and vice versa. Understand the different representations of an integer.
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)
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.
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)
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Computer Organization 1 Data Representation Negative Integers.
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
{ Binary “There are 10 types of people in the world: Those who understand binary, and those who don't.”
Advanced Binary b. describe and use two’s complement and sign and magnitude to represent negative integers; c. perform integer binary arithmetic, that.
Lecture 4: Digital Systems & Binary Numbers (4)
A brief comparison of integer and double representation
Chapter 4 Operations on Bits.
Negative Binary Numbers
Addition and Substraction
Unit 18: Computational Thinking
Number Representation
How are negative and rational numbers represented on the computer?
ECE 331 – Digital System Design
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?

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

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

James Tam Signed Binary 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 representations One's complement Two's complement Positive Negative

James Tam Converting From Unsigned Binary to 1’s Complement For positive values there is no difference e.g., positive seven 0111 (unsigned) For negative values reverse (flip) the bits (i.e., a 0 becomes 1 and 1 becomes 0). e.g., minus six (unsigned) 0111 (1’s complement) 1001 (1’s complement)

James Tam Converting From Unsigned Binary to 2’s Complement For positive values there is no difference e.g., positive seven 0111 (unsigned) 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., minus six (unsigned) 0111 (2’s complement) 1010 (2’s complement)

James Tam Interpreting The Pattern Of Bits Bit patternUnsigned binary1’s complement2's complement

James Tam Overflow: Unsigned Occurs when you don't have enough bits to represent a value Binary (1 bit) Value Binary (2 bits) Value Binary (3 bits) Value

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 Overflow

James Tam Binary Subtraction Unsigned binary subtraction e.g., Subtraction via complements (negate and add) A - B Becomes A + (-B)

James Tam Binary Subtraction Via Negate And Add: A High- Level View What is x – y (in decimal)? I only speak binary

James Tam Binary Subtraction Via Negate And Add: A High- Level View I only do subtractions via complements

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

James Tam Crossing The Boundary Between Unsigned And Signed Unsigned binary One's complement Two's complement Each time that this boundary is crossed (steps 2 & 4) apply the rule: 1)Positive numbers pass unchanged 2)Negative numbers must be converted

James Tam Binary Subtraction Through 1’s Complements 1)Negate any negative numbers (flip the bits) to convert to 1's complement 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 unsigned 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 (flip the bits) and precede the number with a negative sign

James Tam Binary subtraction through 1’s complements e.g Step 1: Negate Step 2: Add no.’s Step 3: Check for overflow ______ +1 2 Step 3: Add it back in Step 4: Check MSB

James Tam Binary subtraction through 1’s complements e.g Step 1: Negate Step 2: Add no.’s ______ +1 2 Step 3: Add it back in Leave it alone

James Tam Binary subtraction through 2’s complements 1)Negate any negative numbers to convert from unsigned binary to 2's complement values a)Flip the bits. b)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 unsigned 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 (flip the bits and add one) and precede the number with a negative sign

James Tam Binary subtraction through 2’s complements e.g Step 1A: flip bits Step 2: Add no’s Step 3: Check for overflow Step 1B: add

James Tam Binary subtraction through 2’s complements e.g Step 1A: flip bits Step 2: Add no’s Step 1B: add

James Tam Binary subtraction through 2’s complements e.g Step 1A: flip bits Step 2: Add no’s Step 4: Check MSB Step 1B: add Step 3: Discard it

James Tam Binary subtraction through 2’s complements e.g Step 1A: flip bits Step 2: Add no’s Step 1B: add Step 4: Leave it alone

James Tam Representing Real Numbers Via Floating Point Numbers are represented through a sign bit, a base 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 (base) Exponent Floating point numbers may result in a loss of accuracy!

James Tam Summary 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 What is meant by overflow How to perform binary subtractions via the negate and add technique. How are real numbers represented through floating point representations