1 / 15

Overflow

Overflow. Range of whole numbers We can check the range of whole numbers of a computer using the following formula: Example, for an 8-bit, the range is as follows: -2⁸⁻¹ to +2⁸⁻¹ - 1 = -2⁷ to +2⁷ - 1 = -128 to +127. What is overflow?

oceana
Download Presentation

Overflow

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Overflow

  2. Range of whole numbers • We can check the range of whole numbers of a computer using the following formula: • Example, for an 8-bit, the range is as follows: -2⁸⁻¹ to +2⁸⁻¹ - 1 = -2⁷ to +2⁷ - 1 = -128 to +127

  3. What is overflow? • Overflow or arithmetic overflow is a condition that occurs when a calculation produces a result that is greater in magnitude than what a given data type can store or represent.

  4. How to identify the condition of occurrence of overflow? • Assuming we’re dealing with an 8-bit computer, let’s look at the situations below: • 65 + 65 = +130 (An occurrence of overflow!) • +128 – 5 = +123 (An occurrence of overflow!) • Hence, an overflow occurs when the input or output exceeds the range of the whole number of the bits contained which is between -128 to +127.

  5. Exercise • Perform the binary addition by showing the step by step process and state if there is an overflow 8-bits • +160 + 123 • -189 + 150 • -74 + 122

  6. Floating point

  7. Floating point describes a system for representing numbers that would be too large or too small to be represented as integers. • Numbers are in general represented approximately to a fixed number of significant digits and scaled using an exponent. • The base for the scaling is normally 2, 10 or 16. • The typical number that can be represented exactly is of the form: significand digits × baseexponent • The term floating point refers to the fact that the radix point (decimal point, or, more commonly in computers, binary point) can "float"; that is, it can be placed anywhere relative to the significant digits of the number.

  8. Single and Double Precision • There are two most common floating point storage format:

  9. How do floating-numbers stored? The Sign • The sign of a binary floating-point number is represented by a single bit. • A 1 bit indicates a negative number, and a 0 bit indicates a positive number.

  10. The Mantissa • The mantissa, also known as the significand, represents the precision bits of the number. • The mantissa of a floating-point number is expressed as a binary number. • A normalized mantissa has its binary point (the base-two equivalent of a decimal point) just to the left of the most significant non-zero digit. Because the binary number system has just two digits; zero and one, the most significant digit of a normalized mantissa is always a one. • E.g. of a normalized mantissa: 1.101 • The mantissa occupies the 23 least significant bits of a single and the 52 least significant bits of a double. The mantissa bits are shown as "m“. Most significant digit

  11. The Exponent • IEEE Short Real exponents are stored as 8-bit unsigned integers with a bias of 127.   • The binary exponent is unsigned, and therefore cannot be negative. The stored form of the exponent is an 8-bit value from 0 to 255. The actual value of the exponent is calculated by subtracting 127 from the stored value (0 to 255) giving a range of –127 to +128. The approximate range is from 1.0 x 2-127 to 1.0 x 2+128. 

  12. While the exponent can be positive or negative, in binary formats it is stored as an unsigned number that has a fixed "bias" added to it. • The exponent bias for single precision is 127 and for double precision is 1023. • The bias is 2k−1 − 1, where k is the number of bits in the exponent field. For the eight-bit format, k = 3, so the bias is 23−1 − 1 = 3. For IEEE 32-bit, k = 8, so the bias is 28−1 − 1 = 127.

  13. The binary value stored in the IEEE floating point number • To calculate the floating point numbers for known width of mantissa and exponent, we use this formula: Value = (-1)sign x (1.mantissa) x 2exponent-bias • E.g.: 1 00001100 10001110000000000000000 s= 1 e= 00001100 = 12 m= 1000111 Value = (-1)s x (1.m) x 2e-127 = (-1)1 x (1.1000111) x 212-127 = -1.1000111 x 2115 The last digit ‘1’ bit The starting bit of mantissa which is after the exponent. The mantissa take only the bits from the starting bit of the mantissa and stop at the last digit‘1’.

  14. The floating pointstored in the binary value • To find the floating point numbers from a binary value, we use this formula: Value = (-1)sx (1.m) x 2e-bias • E.g.: 1.1101 x 220 Hence, s = 0, since the sign is positive m = 11010000000000000000000 ANS: 0 10010011 11010000000000000000000 e = 20 20 = e – 127 e = 20 + 127 e = 147 147 change to binary (8-bits for single precision) is 10010011. Hence, e = 10010011 The mantissa is the number after the decimal (fraction) which is 1101. Since the mantissa for a single precision is 23 bits, hence add 0 to the 1101 until it is 23 bits

  15. Exercise • Find the binary value stored in the floating point number: • 1 00110010 11000100000000000000000 • 0 10000011 10001000000000000000000 • From the binary number, obtain the floating point number: • 1.0011 x 228 • -1.11001 x 290

More Related