Unformatted text preview:

Arithmetics Computer Architecture CS 215 Data Representation Method of storing data using binary codes Fixed Point Numbers Floating Point Numbers Overflow Fixed Point Numbers Range Distance between highest and lowest values Precision Distance between two adjacent values Error Half the precision Fixed Point Numbers Example Assume three digit unsigned decimal numbers Lowest value 0 00 Highest value 9 99 Range 0 00 9 99 9 99 Precision 1 23 1 22 0 01 Error 0 01 2 0 005 Associate Law of Algebra Digital Representations Assume one digit numbers Range 9 9 Try 7 4 3 7 4 3 7 1 8 7 4 3 11 3 Overflow Oops Associate Law of Algebra Digital Representations Either identify overflow and terminate process or Repeat computation with higher precision numbers Radix Number Systems Radix Base Numbers of possible choices for each digit Most systems use base 2 while many calculators use base 10 internally Octal Base 8 Hexadecimal Base 16 Radix Number Systems Weighted position code Polynomial method of conversion n 1 Value i m bi k i Radix Number Systems 1234 567 Most significant digit Least significant digit Converting Among Radices Converting integer part Remainder method Converting fractional part Multiplication method Remainder Method 23 10 10111 Integer 2 23 2 11 2 5 2 2 2 2 1 1 2 0 Remainder 11 1 5 1 1 0 1 Multiplication Method 375 10 011 2 375 x2 0 75 75 x 2 1 5 5 x 2 1 0 Try this Convert the following to radix 2 Show all work 1 123 875 10 2 11 01 10 3 10 2 10 Non terminating Fractions Converting 2 10 to a radix 2 2 x 2 0 4 4 x 2 0 8 8 x 2 1 6 6 x 2 1 2 2 x 2 0 4 And so on Signed Fixed Point Numbers Encoding Schemes Signed Magnitude One s Compliment Two s Compliment Excess Representation Binary Coded Decimal Signed Magnitude Aka sign magnitude First bit for sign 0 is positive 1 is negative Remaining bits for absolute magnitude Two different zeros 0 and 0 28 1 255 different numbers 12 10 00001100 2 One s Compliment Method Negate the positive of the number Compliment all of the bits Not commonly used Difficult for comparisons 2 zeros 28 1 255 different numbers Two s Compliment Method Negate the positive of the number Compliment all of the bits Add binary 1 Discard any carry out Only one zero 28 256 different numbers Excess Representation Aka biased representation Number is treated as unsigned Bias is lowest value in the range Shifted in value by subtracting bias from it Only one zero 28 256 different numbers Excess 127 127 10 00000000 2 Try this Convert the following numbers to one s compliment two s compliment and excess 127 64 75 101 0 FYI Binary Coded Decimal Each decimal digit gets four bits 9 s compliment Subtract each digit from 9 10 s compliment Add 1 to the 9 s compliment FYI Binary Coded Decimal 9 s 10 s compliment 0000 010100010000 0 10 5 10 1 10 0 10 What would 510 10 look like in 9 s compliment form 10 s Compliment Floating Point Numbers Allows for a large range of expressible numbers using a small quantity of digits Uses different digits for precision and Exponent range Ex 6 023 x 1023 Mantissa significand Range Precision To increase range Use fewer digits for mantissa more for exponent Reduces precision Or Increase base Increases precision of smaller numbers decrease precision of larger numbers Normalization the Hidden Bit All floating point numbers are normalized Radix point is set to right of the leftmost nonzero digit in base 2 This results in a 1 as the leftmost digit in the mantissa Dropping this 1 hidden bit increases precision Normalization the Hidden Bit Normalize and account for a hidden bit in the following 0 3 x 102 Floating Point Example Mantissa Signed magnitude form Base 2 Three hexadecimal digits Exponent Three bits Base 2 Excess 4 Simplifies addition subtraction Floating Point Example What would 358 10 look like in our format Floating Point Example Step 1 Convert to base 16 IntegerRemainder 358 16 22 6 22 16 1 6 1 16 0 1 358 10 166 16 Floating Point Example Step 2 Normalize 0 0 0 10 1 1 0 0 1 1 0 16 x 20 10 1 1 0 0 1 1 16 x 29 Hidden Step 3 Represent exponent usingbit bits 011 3 10 Excess 4 1 0 0 111 4 10 Floating Point Example Step 4 Express mantissa using bits 011001100000 Result 0111011001100000 Sign bit Expone nt Mantiss a Error in Floating Point Numbers In our example The base b is 2 There are 3 significant digits s The range of exponents m M is 22 22 1 Error in Floating Point Numbers 5 characteristics Number of representable numbers Number with largest magnitude Number with smallest magnitude Largest gap between successive numbers Smallest gap between successive numbers FYI Representable Numbers 2 M m 1 b 1 b s 1 1 Sign bit Number of exponents First digit of fraction Remaining digits of fraction Zero FYI Largest Magnitude Largest exponent bM Largest fraction All 1 s or 1 b s Largest magnitude is bM x 1 b s FYI Smallest Magnitude Smallest exponent bm Smallest non zero normalized fraction Which is 1 or b 1 Smallest magnitude is bm b 1 bm 1 FYI Largest Gap Largest exponent and Least significant bit changes bM x b s bM s FYI Smallest Gap Smallest exponent and Least significant bit changes bm x b s bm s FYI In our example Largest magnitude bM x 1 b s 21 x 1 2 3 7 4 Smallest magnitude Largest gap bM s 21 3 1 4 Smallest gap bm 1 2 2 1 1 8 bm s 2 2 3 1 32 Representable numbers 2 x M m 1 x b 1 x bs 1 1 2 x 1 2 1 x 2 1 x 23 1 1 33 FYI Error in Floating Point Numbers Relative error is approximately the same for all numbers bM s M s b 1 b m s b m s b 1 b s b s 1 b 1 s b 1 Unsigned Multiplication x 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 1 1 1 0 1 0 0 0 1 1 1 0 1 1 1 1 1 Add Shift then add Shift Shift then add Unsigned Multiplication m3 m2 m1 m0 4 bit Adder c a3 a2 a1 a0 Shift Add Control Logic q3 q2 q1 q0 Unsigned Multiplication C A Q 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 0 1 Add M to A Shift 1 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 1 0 Add M to A Shift 0 0 1 0 0 1 1 1 1 Shift 1 0 0 0 …


View Full Document

WCSU CS 215 - Arithmetics

Documents in this Course
Load more
Loading Unlocking...
Login

Join to view Arithmetics 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 Arithmetics 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?