מבנה מחשב תרגול 2 ייצוג מספרים רציונליים. תמר שרוט, נועם חזון Fixed Point vs. Floating Point We’ve already seen two ways to represent a positive integer.

Slides:



Advertisements
Similar presentations
Fixed Point Numbers The binary integer arithmetic you are used to is known by the more general term of Fixed Point arithmetic. Fixed Point means that we.
Advertisements

Lecture - 2 Number systems and computer data formats
Representing fractions – Fixed point The problem: How to represent fractions with finite number of bits ?
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
Floating Point Numbers
Floating Point Numbers. CMPE12cGabriel Hugh Elkaim 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or.
Computer ArchitectureFall 2007 © September 5, 2007 Karem Sakallah CS 447 – Computer Architecture.
Floating Point Numbers. CMPE12cCyrus Bazeghi 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or 2 64.
Booth’s Algorithm.
Chapter 5 Floating Point Numbers. Real Numbers l Floating point representation is used whenever the number to be represented is outside the range of integer.
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
Floating Point Numbers
Floating Point Numbers
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Computer Science 210 Computer Organization Floating Point Representation.
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
Binary Representation and Computer Arithmetic
The Binary Number System
Data Representation Number Systems.
Simple Data Type Representation and conversion of numbers
Ch. 2 Floating Point Numbers
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Factional Values What is 0.75 in binary?. How could we represent fractions? In decimal: – As fractions : 1/5.
Computer Math CPS120: Data Representation. Representing Data The computer knows the type of data stored in a particular location from the context in which.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
IT253: Computer Organization
Computer Architecture
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Fixed and Floating Point Numbers Lesson 3 Ioan Despi.
16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 © Barnette ND, McQuain WD, Keenan MA 1 Binary Number System Base.
Fractions in Binary.
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
IT1004: Data Representation and Organization Negative number representation.
Fixed-point and floating-point numbers Ellen Spertus MCS 111 October 4, 2001.
Binary & Normalization What is Normalization? We discussed this the other day (special review session slides, near the end) Can someone tell us.
Learning Objectives 3.3.1f - Describe the nature and uses of floating point form 3.3.1h - Convert a real number to floating point form Learn how to normalise.
Starter Using two’s Complement form convert the following from Denary to Binary using 8 bits. Answer on mini whiteboard Using two’s.
Chapter 9 Computer Arithmetic
CSCI206 - Computer Organization & Programming
Floating Point Numbers
Nat 4/5 Computing Science Lesson 1: Binary
Department of Computer Science Georgia State University
Fundamentals of Computer Science
A brief comparison of integer and double representation
Introduction To Computer Science
Recap Add these numbers together in binary
Floating Point Math & Representation
Floating Point Numbers: x 10-18
Computer Science 210 Computer Organization
Floating Point Number system corresponding to the decimal notation
William Stallings Computer Organization and Architecture 7th Edition
Computer Science 210 Computer Organization
CSCI206 - Computer Organization & Programming
Number Representations
CSCI206 - Computer Organization & Programming
Computer Science 210 Computer Organization
ECEG-3202 Computer Architecture and Organization
Chapter 8 Computer Arithmetic
Numbers representations
Representation of real numbers
Number Representations
Presentation transcript:

מבנה מחשב תרגול 2 ייצוג מספרים רציונליים

תמר שרוט, נועם חזון Fixed Point vs. Floating Point We’ve already seen two ways to represent a positive integer in computer hardware: signed and unsigned. Both ways were with a fixed point representation - the location of the binary point was fixed:

תמר שרוט, נועם חזון Floating Point Going back to decimal… Sometimes it is more comfortable to represent a value using a floating point.  For instance: Generally, we use the form Mantissa Base Exponent

תמר שרוט, נועם חזון Floating Point If we look at 123:  The same goes for (fixed point) : 

תמר שרוט, נועם חזון Floating Point Using the form: 

תמר שרוט, נועם חזון Binary Rationals Converting from any radix to decimal is done as before.  So, for instance, the binary number :

תמר שרוט, נועם חזון Binary Rationals For converting from decimal to binary, we’ll use a polynomial of base 2:  So, for instance to binary: What about converting to floating point?

תמר שרוט, נועם חזון Binary Rationals Here, of course In order to transform the result to floating point, we’ll continue from here:

תמר שרוט, נועם חזון Binary Rationals Problem: how can we convert simple fractions to binary? Binary representation might require infinite number of digits.  For example:  We have an algorithm.

תמר שרוט, נועם חזון Algorithm for Simple Fractions write “0.” while (true) do:  If Break  else If  write “1”  else write “0”

תמר שרוט, נועם חזון Algorithm for Simple Fractions For instance:  0.  0.0  0.01  And so on…  …

תמר שרוט, נועם חזון Algorithm for Simple Fractions From here, converting to floating point is easy:

תמר שרוט, נועם חזון Binary Rationals Problems:  This algorithms can run to infinity.  Furthermore, we do not have an endless supply of digits. Solution:  Run the main loop the number of times as the number of digits you have for the fraction part.

תמר שרוט, נועם חזון Fixed Algorithm for Simple Fractions write “0.” for each available digit to fraction part do:  If Break  else If  write “1”  else write “0”

תמר שרוט, נועם חזון Mixed Part Numbers For mixed whole and simple fraction parts numbers, like :  Convert the integer part to binary as we learned on integers.  Convert the fraction part as learned now.  Add the results.  Only now, if desired, convert to floating point.

תמר שרוט, נועם חזון Float vs. Double So how many digits do we really have? Depends on the representation. We have two possible representations for floating point values: 4-byte float and 8-byte double. It all depends on the amount of accuracy we need.

תמר שרוט, נועם חזון Hidden Bit As mentioned before, we use the form: Where In decimal, every digit would have values in the range 0..9 besides which have values in range Likewise, in binary, could only have the value of 1. So why should we save it? Since we won’t save it, we’ll refer to it as the “hidden bit”

תמר שרוט, נועם חזון Float 32-bit (4-byte) representation. 1 bit for sign: 1 for negative, 0 for positive. 23 bits for mantissa. 8 bits for the exponent. Important: The true value of a exponent is unsigned exponent representation bit 8 bits23 bits signexponent+127mantissa

תמר שרוט, נועם חזון Float Limitations 0 is represented with mantissa=0 and “computer” exponent=0. Max absolute value (all 1’s in mantissa and exponent): Min absolute value (0 in mantissa and 1 as “computer” exponent): “Computer” exponent=0 and mantissa different from 0 represent sub-normal numbers “Computer” exponent=255 represent and Nan. 1 bit 8 bits23 bits signexponent+127mantissa

תמר שרוט, נועם חזון 64-bit (8-byte) representation. 1 bit for sign: 1 for negative, 0 for positive. 52 bits for mantissa. 11 bits for the exponent. Important: The true value of a exponent is unsigned exponent representation Double 1 bit 11 bits52 bits signexponent+1023mantissa

תמר שרוט, נועם חזון 0 is represented with mantissa=0 and “computer” exponent=0. Max absolute value (all 1’s in mantissa and exponent): Min absolute value (0 in mantissa and 1 as “computer” exponent): “Computer” exponent=0 and mantissa different from 0 represent sub-normal numbers “Computer” exponent=2047 represent and Nan. Double Limitations 1 bit 11 bits52 bits signexponent+1023mantissa

תמר שרוט, נועם חזון Examples (1) Convert the following float to decimal:  0xc =  As float parts:  With hidden bit: (1.)  As decimal:  Real exp.: - 7  Sum up: 1 bit 8 bits23 bits

תמר שרוט, נועם חזון Examples (2) Convert to float:  As polynomial:  Factor out:  As parts: + 3 (1.)  Represented as: …0  Binary exp.: …0 1 bit 8 bits23 bits