CSCI206 - Computer Organization & Programming

Slides:



Advertisements
Similar presentations
Spring 2013 Advising Starts this week! CS2710 Computer Organization1.
Advertisements

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.
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Floating-point Numbers.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Floating Point (FLP) Representation A Floating Point value: f = m*r**e Where: m – mantissa or fractional r – base or radix, usually r = 2 e - exponent.
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
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…
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Binary Representation and Computer Arithmetic
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.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Lecture notes Reading: Section 3.4, 3.5, 3.6 Multiplication
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: November 08, 2004 Lecture Number: 30.
Floating Point in Binary 1.Place Value Chart:
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
IT11004: Data Representation and Organization Floating Point Representation.
Fixed-point and floating-point numbers Ellen Spertus MCS 111 October 4, 2001.
The Hexadecimal System is base 16. It is a shorthand method for representing the 8-bit bytes that are stored in the computer system. This system was chosen.
FLOATING-POINT NUMBER REPRESENTATION
Floating Point. Binary Fractions.
Floating Point Numbers
Floating Point Representations
Fundamentals of Computer Science
Computer Science 210 Computer Organization
Introduction To Computer Science
Computer Architecture & Operations I
Floating Point Representations
CSCI206 - Computer Organization & Programming
Number Systems and Binary Arithmetic
Data Representation Binary Numbers Binary Addition
Lecture 9: Floating Point
Numbers in a Computer Unsigned integers Signed magnitude
ECE 103 Engineering Programming Chapter 3 Numbers
Data Structures Mohammed Thajeel To the second year students
Topic 3d Representation of Real Numbers
Luddy Harrison CS433G Spring 2007
CSCI206 - Computer Organization & Programming
Number Representations
CSCI206 - Computer Organization & Programming
Computer Science 210 Computer Organization
How to represent real numbers
How to represent real numbers
CS 101 – Sept. 4 Number representation Integer Unsigned √ Signed √
Number Representation
Storing Integers and Fractions
COMS 161 Introduction to Computing
Topic 3d Representation of Real Numbers
IT11004: Data Representation and Organization
Numbers with fractions Could be done in pure binary
Computer Organization and Assembly Language
OBJECTIVES After reading this chapter, the reader should be able to :
Number Representations
Lecture 9: Shift, Mult, Div Fixed & Floating Point
Presentation transcript:

CSCI206 - Computer Organization & Programming Introduction to Floating Point Numbers zyBook: 10.5

Real Numbers in Binary Recall the equation describing a positional number system:

Real Numbers in Binary Recall the equation describing a positional number system: This can be extended to real numbers: http://www.virtualnerd.com/pre-algebra/real-numbers-right-triangles/real-and-irrational/define-real-numbers/real-number-definition decimal point!

Examples base 10 0.1 in binary is = 0.5 (base 10)

Real Numbers in Binary Fractions of a power of 2 are easy Other values are represented using the sum of fractions with a power of 2 denominator

Algorithm to Convert Decimal to Binary For decimal to binary integers we divided by 2 and record the remainder. For decimal to binary real numbers we multiply by 2 and record the integer part. Example: convert to binary.

binary digits beginning to the right of the decimal to binary binary digits beginning to the right of the decimal

binary digits beginning to the right of the decimal to binary binary digits beginning to the right of the decimal

binary digits beginning to the right of the decimal to binary binary digits beginning to the right of the decimal

binary digits beginning to the right of the decimal to binary binary digits beginning to the right of the decimal

binary digits beginning to the right of the decimal to binary binary digits beginning to the right of the decimal only work with fractional part!

fraction part is zero, stop! to binary = 0.00011 It appears magic, but the reason behind the algorithm is to find k, such that v * 2^k = 1.0, as v is expressed as b0*2^(-1)+b1*2^(-2) … fraction part is zero, stop!

Convert binary to decimal Convert 0.000112 to decimal 0.000112 == 2-4 + 2-5 == 1/16 + 1/32 == 3/32 == 0.0937510

Number Representation in Computing For a given range of integers, there is a corresponding range of (exact) binary representations Example: the range [0-15] corresponds to the 4-bit binary numbers 0000 through 1111.

Number Representation in Computing Within a range of real numbers, there is no way to encode all possible values. Example: the range [0.0 - 1.0] has an infinite number of points, so we would need an infinite number of bits to represent all of the possible values! As a result, in computing, real numbers are approximate. Activity 24, question 1 - 2

An Observation Many common base 10 real numbers generate an infinite number of binary digits

Fixed vs. Floating Point Approximations

Floating Point Representation Decimal notation Scientific notation 2 2×100 300 3×102 321.7 3.217×102 −53,000 −5.3×104 6,720,000,000 6.72×109 0.2 2×10−1 Floating Point Representation Where S is the sign bit M is a fixed point number (precision of numbers) E is a signed integer (range of numbers) S Exponent Mantissa or Fraction 32 or 64 bit word

IEEE 754 Standard (1985) S Exponent Mantissa One bit for Sign Single precision float (32 bits) 8 bit Exponent 23 bit Mantissa Double precision float (64 bits) 11 bit Exponent 52 bit Mantissa

IEEE 754 Standard (1985) S Exponent Mantissa Mantissa is normalized, meaning it is a fixed point number in the form 1.xxxxxx to save one bit, the 1. is implicit (not represented) Exponent is represented in biased form B = 127 for single B = 1023 for double

IEEE 754 Standard (1985) (normalized) Exponent Mantissa S, E, and M are encoded in the binary word

IEEE754 - Reserved Values Not a Number =

IEEE754 - Example Show 3.14 as a single precision float

3.14 - step 1 write in binary 3.14 == 3 + 0.14 0.14*2 = 0.28 0.28*2 = 0.56 0.56*2 = 1.12 0.12*2 = 0.24 ...... 0.0010......

3.14 - step 1 write in binary need 24 bits for single (52 for double) 3.14 == 11.0010001111010111000011

3.14 - step 2 normalize binary Normalized form is 1.yyyyy 3.14 == 11.0010001111010111000011 == Note a total of 24 bits.

3.14 - step 3 write mantissa & sign 3.14 == M = 10010001111010111000011 S = 0 (positive) Note that the mantissa keeps only 23 bits, the leading bit is always 1, so it is omitted in representation (only!!).

3.14 - step 4 encode exponent 3.14 == Exponent = 1, B = 127, (8 bits) E (biased exponent) = 128 = 1000 0000

3.14 - step 5 write result S = 0 (positive) E = 1000 0000 M = 10010001111010111000011 0 1000 0000 10010001111010111000011 to hex = 0x4048f5c3

Endianness On a little-endian system (Intel, etc), the IEEE754 value is byte & word swapped 0x 40 48 f5 c3 (big endian) 4840 c3f5 0x c3f5 4840 (little endian) Swap bytes and words! float f = 3.14; unsigned char* p = (unsigned char*)&f; printf("%02x%02x %02x%02x\n", *p, *(p+1), *(p+2), *(p+3)); // result: c3f5 4840