====== 2. Integer and floating point number representation and operations ====== * for lecturer: [[..:..:..:internal:tutorials:02:start|tutorial 2]] ===== Exercise outline ===== - integer representation, addition, subtraction, multiplication, division - real number represetation (in IEEE 754) - 1st homework ===== What topics should I repeat before this exercise ===== - logic operations (and, or, invert, rotation, ...) - two's complement code and IEEE 754. - to understand the program from the last class. ===== What shall we do on the second exercise ===== The aim of today's exercise is representation of real and integer numbers in computer and arithmetical operations with them. ===== Tasks ===== - Integer addition and subtraction in two's complement representation * add and subtract two integer numbers. For example 5+(-6) and 5-(-6). * repeat the operations with different numbers and check your results with the computer program from the first exercise. * When the underflow and overflow can happen? How can we detect, that it had occured? - Integer multiplication * multiply two integers, For example 7*6. * is there any difference when multiplying negative numbers? (e.g. -7*6, (-7)*(-6), etc...) * show how to speed-up the multiplier? (use many adders instead repetitively using one). - Integer division * divide integers 42/7, 43/7 * does the algorithm change when we use negative numbers? - Real number representation (IEEE 754) * binary representation of real numbers (float - 32bit, double - 64bit) * show binary representation of -0.75. Check your result with program from the last exercise. * find decimal number for float binary number 0xC0A00000 in IEEE754. * explain who to add numbers 9.999*10^1 and 1.1610*10^(-1) in decimal representation. Assume that it is possible to store only 4 digits in mantisa and 2 digits in exponent. * Hint: 1) align numbers 2) addition 3) normalization 4) round numbers. * in binary representation add 0.5 and -0.4375 * in decimal representation show multiplication of 1.110*10^10 * 9.200*10^(-5) * in binary representation multiply 0.5 and -0.4375 ===== References ===== * [[http://opensource.apple.com/source/gcc_os/gcc_os-1660/gcc/config/fp-bit.c|gcc/config/fp-bit.c]] - Implementation of float point operations with real numbers using fixed point arithmetic as used in [[http://gcc.gnu.org|GCC]] compiler. Used on processors without hardware floating point support. /* * [[courses:a0b36apo:solutions:02:start]]*/