Numerical Representations On The Computer: Negative And Rational Numbers

Similar documents
Numerical Representations On The Computer: Negative And Rational Numbers

COMP Overview of Tutorial #2

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

A Level Computing. Contents. For the Exam:

Introduction to Computer Science-103. Midterm

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

Chapter 4. Operations on Data


Introduction to Computers and Programming. Numeric Values

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Number representations

Chapter Three. Arithmetic

MC1601 Computer Organization

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

CS101 Lecture 04: Binary Arithmetic

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

World Inside a Computer is Binary

Chapter 3: Arithmetic for Computers

Chapter 3: part 3 Binary Subtraction

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

Signed Binary Numbers

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Inf2C - Computer Systems Lecture 2 Data Representation

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Binary Addition & Subtraction. Unsigned and Sign & Magnitude numbers

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Organisasi Sistem Komputer

CHW 261: Logic Design

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

MACHINE LEVEL REPRESENTATION OF DATA

COMP2611: Computer Organization. Data Representation

FLOATING POINT NUMBERS

4/8/17. Admin. Assignment 5 BINARY. David Kauchak CS 52 Spring 2017

Number Systems. Both numbers are positive

Question 4: a. We want to store a binary encoding of the 150 original Pokemon. How many bits do we need to use?

MAT 106: Trigonometry Brief Summary of Function Transformations

Chapter 2 Bits, Data Types, and Operations

The type of all data used in a C (or C++) program must be specified

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

Chapter 10 Binary Arithmetics

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

CO212 Lecture 10: Arithmetic & Logical Unit

Number System. Introduction. Decimal Numbers

Data Representation in Computer Memory

MYcsvtu Notes DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

±M R ±E, S M CHARACTERISTIC MANTISSA 1 k j

104 - Introduction to Computer Science - Midterm Exam

Floating Point Arithmetic

Digital Fundamentals

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0

Arithmetic for Computers

More Programming Constructs -- Introduction

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

Numeric Encodings Prof. James L. Frankel Harvard University

Number Systems and Their Representations

Divide: Paper & Pencil

Module 2: Computer Arithmetic

C NUMERIC FORMATS. Overview. IEEE Single-Precision Floating-point Data Format. Figure C-0. Table C-0. Listing C-0.

Chapter 2 Bits, Data Types, and Operations

9/23/15. Agenda. Goals of this Lecture. For Your Amusement. Number Systems and Number Representation. The Binary Number System

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Number Systems and Number Representation

CS 101: Computer Programming and Utilization

CHAPTER TWO. Data Representation ( M.MORRIS MANO COMPUTER SYSTEM ARCHITECTURE THIRD EDITION ) IN THIS CHAPTER

Floating-point representations

Adding Binary Integers. Part 5. Adding Base 10 Numbers. Adding 2's Complement. Adding Binary Example = 10. Arithmetic Logic Unit

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Floating-point representations

Integer Representation

Five classic components

Number Systems and Number Representation

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

UNIT 7A Data Representation: Numbers and Text. Digital Data

BINARY SYSTEM. Binary system is used in digital systems because it is:

CS61c Midterm Review (fa06) Number representation and Floating points From your friendly reader

CHAPTER 5: Representing Numerical Data

Number Systems CHAPTER Positional Number Systems

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Chapter 2 Bits, Data Types, and Operations

Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

Name: CMSC 313 Fall 2001 Computer Organization & Assembly Language Programming Exam 1. Question Points I. /34 II. /30 III.

Part 2,Number Systems Questions

Chap.3 3. Chap reduces the complexity required to represent the schematic diagram of a circuit Library

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

The type of all data used in a C++ program must be specified

IEEE Standard 754 Floating Point Numbers

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

Chapter 1. Digital Systems and Binary Numbers

Transcription:

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? Subtraction In the real world A - B In the computer A - B

Subtraction In the real world A - B In the computer A - B A + (-B) Not done this way! Representing Negative Numbers Real world - Negative numbers same as the case of positive numbers but precede the number with a negative sign - e.g., -123456. Computer world - Negative numbers employ signed representations.

Magnitude Of Non-Computer Representations All of the digits are used to represent the magnitude of the number - e.g., 175 10, 1001 2 An explicit minus sign is needed to distinguish positive and negative numbers - e.g., 124 10 vs. -124 10 or 100 2 vs. -100 2 Signed Binary: Magnitude 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) Types of signed representations -One's complement -Two's complement

Signed Binary: Magnitude 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) Types of signed representations -One's complement -Two's complement Positive Negative 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 One s or Two s complement value.

Complementing Regular Binary Using The One s Complement Representation For positive values there is no difference (no change is needed) - e.g., positive seven 0111 (regular binary) 0111 (1 s complement equivalent) 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 -0110 (regular binary) 1001 (1 s complement equivalent) Complementing Regular Binary Using The Two s Complement Representation For positive values there is no difference (no change is needed) - e.g., positive seven 0111 (regular binary) 0111 (2 s complement equivalent) 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 -0110 (regular binary) 1010 (2 s complement equivalent)

Interpreting The Pattern Of Bits Bit pattern 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Regular binary 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 s complement 0 1 2 3 4 5 6 7-7 -6-5 -4-3 -2-1 -0 2's complement 0 1 2 3 4 5 6 7-8 -7-6 -5-4 -3-2 -1 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 0 0 1 1 0 0 : : 00 01 10 0 1 2 11 3 00 0 : : 000 0 001 1 010 2 011 3 100 4 101 5 110 6 111 7 000 0 : :

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. - 7-1 + 7 Addition adding two positive numbers results in a negative number. e.g. 7 + 1-8 Summary Diagram Of The 3 Binary Representations

Summary Diagram Of The 3 Binary Representations Overflow Binary Subtraction Via Complement And Add: A High-Level View What is x y (in decimal)? I only speak binary

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

Crossing The Boundary Between Regular And Signed Binary One's complement Regular binary Two's 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 Binary Subtraction Through One s 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

Binary Subtraction Through 1 s Complements - Step 1: Step 2: Complement Add no. s e.g. 00010 2 11101 2 11101 2 1 Step 3: Add it back in 00101 2 +1 2 Step 3: Check for overflow 00110 2 Step 4: Check MSB Step 4: Leave it alone Binary Subtraction Through Two s 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.

Binary Subtraction Through 2 s Complements e.g. - 00010 2 Step 1A: flip bits 11101 2 Step 1B: add 1 11110 2 Step 2: Add no s 11110 2 1 00110 2 Step 3: Check for overflow Binary Subtraction Through 2 s Complements e.g. - 00010 2 Step 1A: flip bits 11101 2 Step 1B: add 1 11110 2 Step 2: Add no s 11110 2 00110 2 Step 3: Discard it

Binary Subtraction Through 2 s Complements e.g. - 00010 2 Step 1A: flip bits 11101 2 Step 1B: add 1 11110 2 Step 2: Add no s 11110 2 00110 2 Step 4: Check MSB Step 4: Leave it alone Representing Real Numbers Via Floating Point Numbers are represented through a sign bit, a mantissa and an exponent Sign Mantissa Exponent Examples with 5 digits used to represent the mantissa: - e.g. One: 123.45 is represented as 12345 * 10-2 - e.g. Two: 0.12 is represented as 12000 * 10-5 - e.g. Three: 123456 is represented as 12345 * 10 1 Floating point numbers may result in a loss of accuracy!

You Should Now Know How negative numbers are represented using 1 s and 2 s complement representations. How to convert regular binary to values into their 1 s or 2 s 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