College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 1 COE1361:

Slides:



Advertisements
Similar presentations
2009 Spring Errors & Source of Errors SpringBIL108E Errors in Computing Several causes for malfunction in computer systems. –Hardware fails –Critical.
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.
ITEC 352 Lecture 7 Binary(2). Review Homework due on Friday Questions Binary Addition Subtraction Encoding.
Faculty of Computer Science © 2006 CMPUT 229 Floating Point Representation Operating with Real Numbers.
1 IEEE Floating Point Revision Guide for Phase Test Week 5.
ECIV 201 Computational Methods for Civil Engineers Richard P. Ray, Ph.D., P.E. Error Analysis.
Fall 2006AE6382 Design Computing1 Numeric Representation in a Computer Learning Objectives Understand how numbers are stored in a computer and how the.
Round-Off and Truncation Errors
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
CSE 378 Floating-point1 How to represent real numbers In decimal scientific notation –sign –fraction –base (i.e., 10) to some power Most of the time, usual.
2 Systems Architecture, Fifth Edition Chapter Goals Describe numbering systems and their use in data representation Compare and contrast various data.
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
Computer Science 210 Computer Organization Floating Point Representation.
Topic 4 Computer Mathematics and Logic
February 26, 2003MIPS floating-point arithmetic1 Question  Which of the following are represented by the hexadecimal number 0x ? —the integer.
Simple Data Type Representation and conversion of numbers
Numbers and number systems
Information Representation (Level ISA3) Floating point numbers.
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
CEN 316 Computer Organization and Design Computer Arithmetic Floating Point Dr. Mansour AL Zuair.
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.
Fixed-Point Arithmetics: Part II
IT253: Computer Organization
Number Systems So far we have studied the following integer number systems in computer Unsigned numbers Sign/magnitude numbers Two’s complement numbers.
Computing Systems Basic arithmetic for computers.
Lecture Overview Introduction Positional Numbering System
Data Representation.
Why does it matter how data is stored on a computer? Example: Perform each of the following calculations in your head. a = 4/3 b = a – 1 c = 3*b e = 1.
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
Data Representation in Computer Systems
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
CSC 221 Computer Organization and Assembly Language
The Hexadecimal Number System and Memory Addressing ISAT 121.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Information Representation: Floating Point Representation.
1 Number Systems Lecture 10 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Problems with Floating-Point Representations Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright.
How a Computer Processes Information. Java – Numbering Systems OBJECTIVE - Introduction to Numbering Systems and their relation to Computer Problems Review.
IEEE Arithmetic UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Computer Arithmetic Floating Point. We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CS 61C L3.2.1 Floating Point 1 (1) K. Meinz, Summer 2004 © UCB CS61C : Machine Structures Lecture Floating Point Kurt Meinz inst.eecs.berkeley.edu/~cs61c.
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
Lecture 4 - Numerical Errors CVEN 302 June 10, 2002.
Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems
Monday, January 14 Homework #1 is posted on the website Homework #1 is posted on the website Due before class, Jan. 16 Due before class, Jan. 16.
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
CS 160 Lecture 4 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
Chapter Two Hardware Basics: Inside the Box ©1999 Addison Wesley Longman2.2 Chapter Outline What Computers Do A Bit About Bits The Computer’s Core: CPU.
Numbers in Computers.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
10/7/2004Comp 120 Fall October 7 Read 5.1 through 5.3 Register! Questions? Chapter 4 – Floating Point.
CS 125 Lecture 3 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
 Computers are 2-state devices › Pulse – No pulse › On – Off  Represented by › 1 – 0  BINARY.
DATA REPRESENTATION Data Types Complements Fixed Point Representations
Module 2.2 Errors 03/08/2011. Sources of errors Data errors Modeling Implementation errors Absolute and relative errors Round off errors Overflow and.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Floating Point Representations
April 2006 Saeid Nooshabadi
A Level Computing Component 2
Chapter 6 Floating Point
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
Presentation transcript:

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 1 COE1361: Computing for Engineers Learning Objectives Understand how numbers are stored in a computer and what the implications are Lecture 1c Precision and accuracy Numbers on a computer Exercises Summary Not in our textbook … pay attention … create your own knowledge base

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 2 Lecture References Online Computer memory – – – Numeric representation – – tm – – ieeefloat.html – node4.html Standards – /

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 3 How Does a Computer Work? In Lecture 1b we looked at: The history of computers The basic hardware structure of a microprocessor How the hardware relates to the software Limitations in representation (precision/accuracy) Binary Representation IEEE Floating Point Relation to Matlab In Lecture 1c (this one), we will consider numeric representation:

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 4 Numbers: Precision and Accuracy Low precision:  = 3.14 High precision:  = Low accuracy:  = High accuracy:  = High accuracy & precision:  = Good Accuracy Good Precision Good Precision Poor Accuracy Good Accuracy Poor Precision Poor Accuracy Poor Precision

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 5 Numbers Numbers we use are DECIMAL (or base 10): –Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 –123 = 1* * *10 0 But we can always use other bases: Octal (base 8): –Digits: 0, 1, 2, 3, 4, 5, 6, 7 –123 = 1* * *8 0 –123 8 = = Binary (base 2): –Digits: 0, 1 –1011 = 1* * * *2 0 – = = –123 8 = = Hexadecimal (base 16): –Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F –123 = 1* * *16 0 – = = – = =

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 6 Computer Memory Results of a computation, graphics, word documents, everything that a computer does must be stored somewhere. That “somewhere” is “memory”. Memory comes in a variety of types and speeds: Cache – in the CPU itself (fastest) RAM - external to the CPU (fast) Disk - physical media, external to the CPU, r/w CDROM - physical media, (slow) Tape - physical media, (slowest) Memory is measured in “bytes” (and kilobytes, megabytes, gigabytes, and terabytes.)

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 7 Inside the Bytes A byte is the smallest memory allocation available. A byte contains 8 bits so that: –Smallest: = 0 10 –Largest: = 1*2 7 +1*2 6 +1*2 5 +1*2 4 +1*2 3 +1*2 2 +1*2 1 +1*2 0 = (or ) Result: a single byte can be used to store an integer number ranging from 0 to 255 (256 different numbers) If negative numbers are included, one bit must be dedicated to the sign, leaving only 7 bits for the number –Smallest: 0 –Largest: or

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 8 Signed-Magnitude (OPTIONAL MATERIAL) Example of signed magnitude: => => - 5 Notice also that signed-magnitude gives plus and minus zero! – => + 0 – => - 0

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 9 Two’s Complement Used (OPTIONAL MATERIAL) If first bit is zero, the number is positive and there is no further interpretation needed: – => If first bit is one, the number is negative. Complement all bits and add one to get to the positive magnitude of the negative number Therefore original number = -1

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 10 Two’s Complement (OPTIONAL MATERIAL) Two’s Complement has no negative zero = - 1, = -128 Range: [ -128, 127 ]

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 11 Inside the Bytes (255) is not a very big number, so computers generally use multiple bytes to represent numbers: Here is some new vocabulary: –byte = 8 bits –short (precision) = 2 bytes –single (precision) = 4 bytes –double (precision) = 8 bytes –quad (precision) = 16 bytes –char = 2 bytes (used to be 1 byte) Note: –A word is the basic size of the CPU registers and for Pentium chips it is 4 bytes or 32 bits; it is 8 bytes for the new Itanium and some unix chipsets. It was 2 bytes for early Intel chips; some new game consoles use 16 byte words. Java and other languages use different names!

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 12 Inside the Bytes How are fractional numbers (called real or floating point numbers) stored in a computer? The IEEE 754 double format consists of three fields: –a 52-bit fraction, f (also called the mantissa) –an 11-bit biased exponent, e –and a 1-bit sign, s These fields are stored contiguously in 8 bytes (or 2 successively addressed 4-byte words):

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 13 Inside the Bytes Because only a finite number of bits are used for each part of the number, not all possible real numbers can be represented in a computer using IEEE Positive numbers smaller than (positive underflow, Matlab “realmin”) Positive numbers greater than ( ) x (positive overflow, Matlab “realmax”) Negative numbers less than -( ) x (negative overflow) Negative numbers greater than (negative underflow) RESULT: about 16 digits of precision in the range ±10 ±308 Zero (actually is a special combination of bits)

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 14 Inside the Bytes Others sources of error in computation: Errors in the input data - measurement errors, errors introduced by the conversion of decimal data to binary, roundoff errors. Roundoff errors during computation (as discussed) Truncation errors - using approximate calculation is inevitable when computing quantities involving limits and other infinite processes on a computer –Never try to compare two floating point numbers for equality because all 16+ digits would have to match perfectly…

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 15 Describing Error in Matlab Accuracy How close your answer is to the “actual” or “real” answer. Precision The smallest difference that can be represented on the computer ( help eps ) Recognize: MATLAB (and other programs that use IEEE doubles) give you “good” digits MATLAB will also store exact integer values using only the mantissa (for about digits total) Matlab commands: realmin, realmax, eps, bitmax (try with help )

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 16 Memory in MATLAB

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 17 What it Means… In the previous slide, we see: What is the size of the variable “i” What does “class” represent? How many bytes are used to store the value? Name Size Bytes Class i 1x1 8 double array s 1x43 86 char array t 1x double array

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 18 Back to MATLAB - what does all this mean? We must pay attention to the math! (on any computer!) Given a finite (limited) number of bits, almost all computations will result in numbers that can’t be represented exactly. Remember that the result of a floating-point computation must be truncated to fit back into it’s finite representation. Always check your results - design programs to allow for independent verification of computations!

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 19 SUMMARY Describe memory. List different kinds of memory. What is IEEE 754? Describe how MATLAB represents numbers. Draw a number line and identify ranges where computers will generate errors. Describe three potential sources of errors in computation. Describe precision. Describe accuracy. Describe how we can protect ourselves from computation error.

College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 20 Summary Action Items Review the lecture How will you use this information in your current work? … future work at GT? Start Exploring Matlab! Increment your record of commands learned Come prepared to ask questions about MATLAB Lecture 1c Numbers on a computer Precision and accuracy