Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numbers and number systems

Similar presentations


Presentation on theme: "Numbers and number systems"— Presentation transcript:

1 Numbers and number systems

2 Radix number systems Some number of positions and some number of symbols The number of positions varies by context The number of symbols is a property of the number system Decimal symbols Binary -- 2 symbols Octal -- 8 symbols Hexadecimal symbols

3 Start with whole numbers
Each position has a value Each symbol has a value Multiply the value of the symbol by the value of the position, then add In decimal, 3874 means 3 times 1,000 plus 8 time 100 plus 7 times 10 plus 4 times 1

4 Decimal, binary, octal, hex
In decimal there are 10 symbols (0..9) and the value of each position is a power of 10. 100 = 1 = value of the units position 101 = 10 = value of next position to the left etc. In binary, there are 2 symbols, 0 and 1, and the value of each position is a power of 2. In octal, 8 symbols, and powers of 8 In hexadecimal, 16 symbols, and powers of 16

5 Converting Binary to/from octal and hex is very easy
mark off groups Decimal is harder, but not very much. Example 3176 to binary, octal, hex 71348 to decimal, binary, hex 5A3216 to decimal, binary, octal

6 Include fractions Same principles
Use negative powers of the base to the right of the radix point. (Only call it a decimal point in the decimal number system.) to binary, octal, hex to decimal, octal, hex to decimal, binary, hex AB1.216 to decimal, binary, octal

7 Negatives Same as positive, but need a way to recognize that the value is negative. What does negative mean? Distance from 0, opposite direction of positive For every positive, there is a corresponding negative. When those are added, the result is exactly 0.

8 Ways to represent negatives
Sign magnitude - or ( ) or red ink or whatever 1’s complement reverse the bits to get the negative (subtract from all 1’s to get the complement) 2’s complement subtract from a power of two  …. 000 (number of places depends on the size of the storage available.) It so happens that reversing the bits and adding 1 accomplishes this subtraction. excess something Add something to the value before storing

9 2’s complement For n bits, each value is expressed relative to its distance from 2n. Technically, that means subtract each value from 2n . Conveniently, that can be accomplished by switching each bit and then adding 1 to the result. For n = 4: subtract from 24 = 10000, show only four bits. Note, 0 comes first, then the positive values, then the negatives.

10 Does this work? Check it out. Example: 3 + 4: Example: -3 + -4:
= 0111 = 7 Example: : = 1) = -7 note that the extra 1 that flows out of the computation is not an overflow. Example: : 0011 = 1100 = 1111 = -1 Examples don’t prove correctness, of course; they are only illustrations

11 Excess something The point of excess something representation for values is that numbers stay in the order you expect the greatest negative is the smallest value 0 is in the middle the greatest positive is the largest value. We will see excess 127 used in representing exponents. The value 43 would be represented as = 170 The value -43 would be represented as = 84 The smaller values (the negatives) start with 0 in binary; the larger values (the positives) start with binary 1. This is the opposite of 2’s complement, where the negatives start with 1 and the positives start with 0.

12 Binary arithmetic - addition
0 + 0 = 0 0 + 1 = 1 Overflow: If there is not enough room to hold the result correctly. An extra bit that drops out is not necessarily an overflow. If the two numbers are of opposite signs, no overflow can occur. (Why not?) If the numbers are of the same sign, overflow occurs if the carry into the sign bit position is different from the carry out of the sign bit position. 1 + 0 = 1 1 + 1 = 0 and carry 1 (Add two small negative nos.) (Result is smaller than one of them) Sign changed as a result of the computation, not because of the signs of the numbers used.

13 Binary arithmetic - multiplication
0 * 0 = 0 0 * 1 = 0 No carry. No big tables to memorize Multiplying negatives: complement, multiply the positives, set the sign appropriately. Size of the product is sum of the sizes of the multiplier and multiplicand. 1 * 0 = 0 1 * 1 = 1

14 Fractions A part of a whole.
Approximation of the real number line, with limitations imposed by the number of places used. Consider a decimal number expressed with not more than 5 decimal places. How would you represent ? Because of the limitation on the representation (only 5 places), we cannot accurately represent this number. Instead, we would use an approximation: This is an example of a roundoff error If we needed to represent the remaining of the number, we are out of luck. This is called underflow

15 Overflow and Underflow
Ref. Tannenbaum. Computer Organization

16 How to represent fractional values in binary
We have only two symbols. We must represent numbers: 0 and 1 sign radix point How do we do that? There have been a number of perfectly good solutions. Now that it is common to exchange data between systems, we must have one common method.

17 Floating point notation
By example (using 8 bit word size): 2.5 = 10.1 in binary One way to represent the point is to put it in the same place all the time and then not represent it explicitly at all. To do that, we must have a standard representation for a value that puts the point in the same place every time. 10.1 = 1.01 * 21 Use 1 bit for sign, 2 bits for exponent, rest for value sign = 0 (positive); exponent = 01; significand = 101 point assumed as in 1.01 Result=

18 Refinement Use 32 or 64 bits, not 8, to make more reasonable range of values Note that the leading 1 (as in 1.01 *21) is always there, so we don’t need to waste one of our precious bits on it. Just assume it is always there. Use excess something notation for handling negative exponents. These ideas came from existing schemes developed for the PDP-11 and CDC 6600 computers.

19 IEEE Standard 754 One way to meet the need, agreed to and accepted by most computer manufacturers. Bits 1 8 23 Single Precision Fraction Sign Exponent Double Precision Bits 1 11 52 Fraction Sign Exponent

20 Steps to IEEE format Convert 35.75, for example
Convert the number to binary Normalize x 25 Fit into the required format = 132; hide the leading 1. Use Hexadecimal to make it easier to read 420F0000

21 Single and double precision
Double precision uses more space, allows greater magnitude and greater precision. Other than that, it behaves just like single precision. We will use only single precision in examples, but any could easily be expanded to double precision.

22 IEEE 754 details Ref. Tannenbaum. Computer Organization

23 What’s normal? Normalized means represented in the normal, or standard, notation. Some numbers do not fit into that scheme and have a separate definition. Consider the smallest normalized value: x 2-126 How would we represent half of that number? x 2-127 But we cannot fit 127 into the exponent field x would do it. But we are stuck with that implied 1 before the implied point So, there are a lot of potentially useful values that don’t fit into the scheme. The solution: special rules when the exponent has value 0 (which represents -126).

24 Denormalization This is denormalization: abandoning the “normal” scheme to exploit possibilities that would otherwise not be available. Any non-zero value Sign No implied 1 before the implied point Power of two multiplier is -127

25 Representing Zero How do you represent exactly 0 if there is an implied 1 in the number somewhere? A special case of denormalized numbers, when everything is zero, the value of the number is exactly 0.0

26 Infinity A special representation is reserved for infinity, because it is a useful entity to have available. 00000… Sign

27 NaN (Not a Number) One more special case reserved for undefined results: Any non-zero bit pattern Sign


Download ppt "Numbers and number systems"

Similar presentations


Ads by Google