90 likes | 207 Views
Data.. Representation & storage Storing Real Numbers Fixed-point Notation Floating-Point (Scientific) Notation. Fractions in the Decimal System (Fixed-Point notation). We represent fractions using the idea of a radix point (called decimal point here), for example 3445.6701;
E N D
Data..Representation & storageStoring Real NumbersFixed-point NotationFloating-Point (Scientific) Notation
Fractions in the Decimal System(Fixed-Point notation) • We represent fractions using the idea of a radix point (called decimal point here), for example 3445.6701; • The fraction part of the number is represented by digits to the right of the radix (in the example these are .6701); • Positions to the right of the radix point carry weights, these weights are negative powers of 10 in the example above .6701 = 6 x 10-1 + 7 x 10-2 + 0 x 10-3 + 1 x 10-4; • Lets copy the same ideas into the binary system How…?
Fractions in Binary System(Fixed-Point notation) • We represent fractions using the idea of a radix point for (can be called binary point here) example 101.1011; • The fraction part of the number is represented by binary digits to the right of the radix (in the example these are .1011); • Positions to the right of the radix point carry weights, these weights are negative powers of 2 in the example above .1011 = 1 x 2-1 + 0 x 2-2 + 1 x 2-3 + 1 x 2-4 = 1 x ½ + 0 x ¼ + 1 x 1/8 + 1 x 1/16 In decimal system this is = 11/16 = (0.6875)10; • The above example illustrates how to convert a binary fraction to an equivalent decimal fraction; • How do we convert a decimal fraction to a binary fraction ?
Fractions in Binary Systemconverting Decimal to Binary • Lets consider a simple example (0.5)10 = (?)2 • We all know this will be (.1)2 • Lets arrive at it in a different way: • Multiply 0.5 by 2 = 1.0 • Ignore the fraction of the result (here it is 0) and take the digit to the left of the decimal point as the digit in position 2-1 in the binary representation; • Another simple example (0.25)10 = (?)2 • 0.25 x 2 = 0.50 • .5 x 2 = 1.0 (since fraction in the result = 0 stop) • The binary equivalent of (0.25)10 = (.01)2 • Another example (0.3)10 = (?)2 …
Fractions in Binary Systemconverting Decimal to Binary cont’d • Another example (0.3)10 = (?)2 ….(0.01001)2 • 0.3 x 2 = 0.6 • 0.6 x 2 = 1.2 • 0.2 x 2 = 0.4 • 0.4 x 2 = 0.8 • 0.8 x 2 = 1.6 • 0.6 x 2 … oops we have a cycle (0.6 appeared earlier), what does that mean ? • (0.3)10 can not be represented by a finite number of bits in the binary system!
Floating-Point NotationHow can we represent very small fractions… • Consider that we have a total of 8 bit to store a number in the binary system; we use 2 bits to store the fraction part, and 6 bits to store the whole part. Ex 101101.10 is a number that can be represented • Question: can we represent 3.125 in that system ? • For the whole part (3) the representation in 6 bits is simple; 000011 • For the fraction part (0.125), lets convert to a binary fraction: .125 x 2 =0.250 .250 x 2=0.5 .5 x 2 = 1.0 the fraction should be (.001)2 • Because we use 2 bits for the fraction part the correct result (000011.001) will be represented as (000011.00); anerror occurs • The fraction .001 is too small to be represented in just 2 bits, the solution?
Floating-point notationPosition of the Radix point • The problem with the previous example is that the first 1 in the fraction part occurs after a number of leading zeros; • In the decimal system Floating-point notation is used to efficiently represent such fractions; • Examples: • 0.00003 is represented as .3 x 10-4 (also written .3 E–4) • 0.0000 0000 625 is represented by .625 E–8; • The Floating-point notation is a way to record the “true” place of the decimal point; • For example, .3E-4 means the decimal point is really 4 places to the left of the digit 3 , i.e. .00003;
Components of a number represented in Floating-point Notation in decimal system • Consider the number 0.625E-4, the components of this number are: • A sign(here the number is positive the sign is + but is omitted); • A Mantissa field; this represents the value of the fraction part (in this case it is .625); • An Exponent; this is how we record the true position of the decimal point (here the exponent is –4, and the true position of the decimal point is thus 4 positions to the left of the most significant digit in the mantissa, i.e. .0000626; • Important: in Floating-point notation the mantissa is made to be always a fraction, for example • 133.625 is represented as .133625E+3.
Floating-Point Notation in the binary system • A number is represented using the same components we discussed , a sign , a mantissa, and an exponent; • Numbers are represented using a fixed number of bits (e.g. 8, 16, 24, etc..); • Bits are used as follows: • The sign is always represented by the most significant bit (0 means positive, 1 means negative); • A number of bits to the right of the sign bit are used to represent the exponent in excess notation; • The remaining bits represent the mantissa as a binary fraction;