CprE 281: Digital Logic

Similar documents
CprE 281: Digital Logic

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

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

IEEE-754 floating-point

CprE 281: Digital Logic

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

M1 Computers and Data

15213 Recitation 2: Floating Point

Description Hex M E V smallest value > largest denormalized negative infinity number with hex representation 3BB0 ---

Representing numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states).

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers

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

Computer Systems Programming. Practice Midterm. Name:

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

CprE 281: Digital Logic

Full Name: CISC 360, Fall 2008 Example of Exam

Computer Systems C S Cynthia Lee

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers

CprE 281: Digital Logic

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

ICS Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2

CS101 Introduction to computing Floating Point Numbers

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

Representing and Manipulating Floating Points. Jo, Heeseung

IEEE Floating Point Numbers Overview

Representing and Manipulating Floating Points

Today CISC124. Building Modular Code. Designing Methods. Designing Methods, Cont. Designing Methods, Cont. Assignment 1 due this Friday, 7pm.

EE 109 Unit 19. IEEE 754 Floating Point Representation Floating Point Arithmetic

Memory, Data, & Addressing I

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

FLOATING POINT NUMBERS

ECE2049: Homework 1. Consider the following code to compute the average of your exam grades: #define NUM_EXAMS (3)

Final Labs and Tutors

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

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

Floating Point Numbers

Floating Point Numbers

CSCI 402: Computer Architectures. Arithmetic for Computers (3) Fengguang Song Department of Computer & Information Science IUPUI.

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

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

IEEE Standard 754 Floating Point Numbers

Binary Representations and Arithmetic

Where are we? Compiler. translating source code (C or Java) Programs to assembly language And linking your code to Library code

Inf2C - Computer Systems Lecture 2 Data Representation

CSE351: Memory, Data, & Addressing I

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

COMP2611: Computer Organization. Data Representation

BSM540 Basics of C Language

ECE2049: Homework 1. Due: Thursday, 25 May 2017 by 7pm

MACHINE LEVEL REPRESENTATION OF DATA

Floating Point Numbers

Representing and Manipulating Floating Points

Recap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio

Floating Point Arithmetic

211: Computer Architecture Summer 2016

CS 33. Data Representation (Part 3) CS33 Intro to Computer Systems VIII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

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

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

CIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm

Digital Computers and Machine Representation of Data

Python Numbers. Learning Outcomes 9/19/2012. CMSC 201 Fall 2012 Instructor: John Park Lecture Section 01 Discussion Sections 02-08, 16, 17

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

Representing and Manipulating Floating Points

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

Computational Methods CMSC/AMSC/MAPL 460. Representing numbers in floating point and associated issues. Ramani Duraiswami, Dept. of Computer Science

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

Where we are going (today)

Floating Point January 24, 2008

3.5 Floating Point: Overview

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Content. Information Coding. Where are we? Where are we? Bit vectors (aka Words )

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

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

Number Representations

Where we are going (today)

COMP2121: Microprocessors and Interfacing. Number Systems

Floating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers.

COMP Overview of Tutorial #2

Course overview. Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18. with slides by Kip Irvine

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

Survey. Motivation 29.5 / 40 class is required

Natural Numbers and Integers. Big Ideas in Numerical Methods. Overflow. Real Numbers 29/07/2011. Taking some ideas from NM course a little further

ECE232: Hardware Organization and Design

Number Systems. The Computer Works in Binary, or how I learned to think like a computer. The computer s natural number system is binary not decimal.

System Programming CISC 360. Floating Point September 16, 2008

CPS 104 Computer Organization and Programming

Under the Hood: Data Representation. Computer Science 104 Lecture 2

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

Data Representation Floating Point

Numerical computing. How computers store real numbers and the problems that result

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

INTEGER REPRESENTATIONS

Memory, Data, & Addressing II

Floating Point Numbers

EE 109 Unit 2. Binary Representation Systems

Data Representation Floating Point

Transcription:

CprE 281: Digital Logic Instructor: Alexander Stoytchev http://www.ece.iastate.edu/~alexs/classes/

Floating Point Numbers CprE 281: Digital Logic Iowa State University, Ames, IA Copyright Alexander Stoytchev

HW 6 is out Administrative Stuff It is due on Monday Oct 9 @ 4pm

The story with floats is more complicated IEEE 754-1985 Standard [http://en.wikipedia.org/wiki/ieee_754]

In the example shown above, the sign bit is zero, the exponent is 124, and the significand is 1.01 (in binary, which is 1.25 in decimal). The represented number is (-1) 0 2 (124-127) 1.25 = +0.15625. [http://en.wikipedia.org/wiki/ieee_754]

Float (32-bit) vs. Double (64-bit) 32 bits S E M Sign 0 denotes 1 denotes + 8-bit excess-127 exponent 23 bits of mantissa (a) Single precision 64 bits S E M Sign 11-bit excess-1023 exponent (b) Double precision 52 bits of mantissa [Figure 3.37 from the textbook]

On-line IEEE 754 Converter https://www.h-schmidt.net/floatconverter/ieee754.html

Representing 2.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 2.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 2.0 128 0 0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 2.0 2 (128-127) (-1) 0 (1 + 0) [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 2.0 (-1) 0 2 (128-127) (1 + 0) = 2.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 2.0 1 2 1 1.0 = 2.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 4.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 4.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 4.0 129 0 0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 4.0 (-1) 0 2 (129-127) (1 + 0) = 4.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 4.0 1 2 2 1.0 = 4.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 8.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 16.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing -16.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 1.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 3.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 3.0 128 0 0.5 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 3.0 (-1) 0 2 (128-127) (1 + 0.5) = 3.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 3.0 1 2 1 1.5 = 3.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 3.5 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 3.5 128 0 0.5 + 0.25 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 3.5 (-1) 0 2 (128-127) (1 + 0.5 + 0.25) = 3.5 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 3.5 1 2 1 1.75 = 3.5 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 5.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 6.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing -7.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 0.8 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 0.8 This decimal number cannot be stored perfectly in this format! The bits in the mantissa are periodic and will extend to infinity. Think of storing 1/3 = 0.33333(3) with fixed number of decimal digits. This is similar: 0.8 10 has no finite representation in IEEE 754. [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing 0.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing -0.0 [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing +Infinity [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing -Infinity [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing NaN [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing NaN [http://www.h-schmidt.net/floatapplet/ieee754.html]

Representing NaN [http://www.h-schmidt.net/floatapplet/ieee754.html]

[http://babbage.cs.qc.cuny.edu/ieee-754.old/references.xhtml]

Conversion of fixed point numbers from decimal to binary [Figure 3.44 from the textbook]

Sample Midterm2 Problem

Sample Midterm2 Problem

Sample Midterm2 Problem

Sample Midterm2 Problem

Memory Analogy Address 0 Address 1 Address 2 Address 3 Address 4 Address 5 Address 6

Memory Analogy (32 bit architecture) Address 0 Address 4 Address 8 Address 12 Address 16 Address 20 Address 24

Memory Analogy (32 bit architecture) Address 0x00 Address 0x04 Address 0x0A Address 0x08 Address 0x0C Address 0x10 Address 0x14 Address 0x0D Address 0x18 Hexadecimal

Storing a Double Address 0x08 Address 0x0C

Storing 3.14 3.14 in binary IEEE-754 double precision (64 bits) sign exponent mantissa 0 10000000000 1001000111101011100001010001111010111000010100011111 In hexadecimal this is (hint: groups of four): 0100 0000 0000 1001 0001 1110 1011 1000 0101 0001 1110 1011 1000 0101 0001 1111 4 0 0 9 1 E B 8 5 1 E B 8 5 1 F

Storing 3.14 So 3.14 in hexadecimal IEEE-754 is 40091EB851EB851F This is 64 bits. On a 32 bit architecture there are 2 ways to store this Small address: 40091EB8 51EB851F Large address: 51EB851F 40091EB8 Big-Endian Little-Endian Example CPUs: Motorola 6800 Intel x86

Storing 3.14 Address 0x08 Address 0x0C 40 09 1E B8 51 EB 85 1F Big-Endian Address 0x08 51 EB 85 1F Address 0x0C 40 09 1E B8 Little-Endian

Storing 3.14 on a Little-Endian Machine (these are the actual bits that are stored) Address 0x08 01010001 11101011 10000101 00011111 Address 0x0C 01000000 00001001 00011110 10111000 Once again, 3.14 in IEEE-754 double precision is: sign exponent mantissa 0 10000000000 1001000111101011100001010001111010111000010100011111

They are stored in binary (the hexadecimals are just for visualization) Address 0x08 5 1 E B 8 5 1 F 01010001 11101011 10000101 00011111 Address 0x0C 4 0 0 9 1 E B 8 01000000 00001001 00011110 10111000

Big-Endian (8-bit architecture) (16-bit architecture) http://en.wikipedia.org/wiki/endianness

Little Endian (8-bit architecture) (16-bit architecture) http://en.wikipedia.org/wiki/endianness

Big-Endian/Little-Endian analogy [image fom http://www.simplylockers.co.uk/images/plowlocker.gif]

Big-Endian/Little-Endian analogy [image fom http://www.simplylockers.co.uk/images/plowlocker.gif]

Big-Endian/Little-Endian analogy [image fom http://www.simplylockers.co.uk/images/plowlocker.gif]

What would be printed? (don t try this at home) double pi = 3.14; printf( %d,pi); Result: 1374389535 Why? 3.14 = 40091EB851EB851F (in double format) Stored on a little-endian 32-bit architecture 51EB851F (1374389535 in decimal) 40091EB8 (1074339512 in decimal)

What would be printed? (don t try this at home) double pi = 3.14; printf( %d %d, pi); Result: 1374389535 1074339512 Why? 3.14 = 40091EB851EB851F (in double format) Stored on a little-endian 32-bit architecture 51EB851F (1374389535 in decimal) 40091EB8 (1074339512 in decimal) The second %d uses the extra bytes of pi that were not printed by the first %d

What would be printed? (don t try this at home) double a = 2.0; printf( %d,a); Result: 0 Why? 2.0 = 40000000 00000000 (in hex IEEE double format) Stored on a little-endian 32-bit architecture 00000000 (0 in decimal) 40000000 (1073741824 in decimal)

What would be printed? (an even more advanced example) int a[2]; // defines an int array a[0]=0; a[1]=0; scanf( %lf, &a[0]); // read 64 bits into 32 bits // The user enters 3.14 printf( %d %d, a[0], a[1]); Result: 1374389535 1074339512 Why? 3.14 = 40091EB851EB851F (in double format) Stored on a little-endian 32-bit architecture 51EB851F (1374389535 in decimal) 40091EB8 (1074339512 in decimal) The double 3.14 requires 64 bits which are stored in the two consecutive 32-bit integers named a[0] and a[1]

Questions?

THE END