GT AE 6382 - Numeric Representation in a Computer

Unformatted text preview:

Numeric Representation in a ComputerNumbers: precision and accuracyComputer MemoryComputer Memory is Varied…Memory in MATLABInside the BytesNumbers and their BasesSlide 8Slide 9Inside the Bytes: ExerciseSlide 11Slide 12Slide 13Describing errorInside the bytesSUMMARYNumeric computation in MATLABSimple Math and EvaluationPractice: Simple CalculationsVariables and NamesPractice: simple computationsWhere are Variables Stored?How are numbers displayed?MATLAB Built-in FunctionsPractice: Matlab ExpressionsSummaryLecture references onlineMATLAB commands usedFall 2006AE6382 Design Computing 1Numeric Representation in a ComputerLearning ObjectivesUnderstand how numbers are stored in a computer and how the computer operates on them.•Topics•Numbers on a computer•Precision and accuracy•Numeric operators•Precedence•Exercises•SummaryFall 2006AE6382 Design Computing 2Numbers: precision and accuracy•Low precision:  = 3.14•High precision:  = 3.140101011•Low accuracy:  = 3.10212•High accuracy:  = 3.14159•High accuracy & precision:  = 3.141592653Good Accuracy Good PrecisionGood PrecisionPoor AccuracyGood AccuracyPoor PrecisionPoor AccuracyPoor PrecisionFall 2006AE6382 Design Computing 3Computer Memory•Numbers and the results of numeric computations (along with other data such as text, graphics, documents, etc) must be stored somewhere in a computer.•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.)Fall 2006AE6382 Design Computing 4Computer Memory is Varied…Fall 2006AE6382 Design Computing 5Memory in MATLABFall 2006AE6382 Design Computing 6Inside the Bytes•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 k 1x1 8 double array s 1x12 24 char array x 1x200 1600 double arrayGrand total is 213 elements using 1632 bytesFall 2006AE6382 Design Computing 7Numbers and their Bases•Numbers we use are DECIMAL (or base 10):–Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9–123 = 1*102 + 2*101 + 3*100 •But we can always use other bases:•Octal (base 8):–Digits: 0, 1, 2, 3, 4, 5, 6, 7–123 = 1*82 + 2*81 + 3*80–1238 = 64+16+3 = 8310•Binary (base 2):–Digits: 0, 1–1011 = 1*23 + 0*22 + 1*21 + 1*20–10112 = 8+0+2+1 = 1110–1238 = 001 010 011 = 10100112•Hexidecimal (base 16):–Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F–123 = 1*162 + 2*161 + 3*160–12316 = 256 + 32 + 3 = 29110–12316 = 0001 0010 0011 = 1001000112Fall 2006AE6382 Design Computing 8Inside the Bytes•A byte is the smallest memory allocation available.•A byte contains 8 bits so that:–Smallest: 0 0 0 0 0 0 0 0 = 010–Largest: 1 1 1 1 1 1 1 1 = 1*27+1*26+1*25+1*24+1*23+1*22+1*21+1*20 = 25510 (or 28-1)•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: +12710 or -12810Fall 2006AE6382 Design Computing 9Inside the Bytes•2^8-1 (255) is not a very big number, so computers generally use multiple bytes to represent numbers:•Here is some vocabulary:–byte = 8 bits–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 game consoles use 16 byte words.Fall 2006AE6382 Design Computing 10Inside the Bytes: Exercise•Let’s investigate how MATLAB stores numbers:•Try the following MATLAB commands:•format short•2^8•2^8-1 %(is the answer correct?)•2^64•2^64-1 % (is the answer correct?)•Question: what is the largest value of the exponent so that the answer above is correct?Fall 2006AE6382 Design Computing 11Inside the Bytes•How are fractional (floating point) numbers stored in a computer?•The IEEE 754 double format consists of three fields:–a 52-bit fraction, f–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):Fall 2006AE6382 Design Computing 12Inside the Bytes•Because only a finite number of bits can be used for each number, not all possible numbers can be represented:•Negative numbers less than -(2-2-52) x 21023 (negative overflow) •Negative numbers greater than -2-1022(negative underflow) •Positive numbers less than 2-1022 (positive underflow) •Positive numbers greater than (2-2-52) x 21023 (positive overflow) •Zero (actually is a special combination of bits)Fall 2006AE6382 Design Computing 13Inside 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.•Roundof 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…Fall 2006AE6382 Design Computing 14Describing error•Precision•The smallest difference that can be represented on the computer (help eps)•Accuracy•How close your answer is to the “actual” or “real” answer.•Recognize:•MATLAB (and other programs that use IEEE doubles) give you 15-16 “good” digits•MATLAB COMMANDS•realmin, realmax, eps (try with help)Fall 2006AE6382 Design Computing 15Inside the bytes•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,•Remember that the result of a floating-point computation must be ROUNDED to fit back


View Full Document

GT AE 6382 - Numeric Representation in a Computer

Download Numeric Representation in a Computer
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Numeric Representation in a Computer and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Numeric Representation in a Computer 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?