Fix point numbers and Floating point numbers

12.1.1.6 use binary numbers with a fixed point to represent fractional numbers with a given number of bits. 

12.1.1.7 represent positive and negative floating-point decimal numbers in binary. 

Fix point numbers and Floating point numbers

Fix point numbers

Real number - a number with a fractional part.

The number 68.25 represents 6 tens, 8 units, 2 tenths, 5 hundredths.

In binary, the equivalent place values are 

128  64  32  16  8  4  2  1  .  1/2  1/4  1/8  1/16

The number 68/25 can be expressed as 68 + 1/4, and using the place values above converts to

Matching binary fraction and decimal fraction

Binary fraction Fraction Decimal fraction
0.1 1/2 0.5
0.01 1/4 0.25
0.001 1/8 0.125
0.0001 1/16 0.0625
0.00001 1/32 0.03125
0.000001 1/64 0.015625

Floating point numbers

Why do we use float point real numbers?

1) a very large number

600 000 000 000 000 = 0.6 х 1015

2) a very small number

0.000 000 000 03 = 0.3 х 10-10

Example of a denary floating-point number

Example of a binary floating-point number

Why use binary floating-point numbers

Fixed point binary allows a computer to hold fractions but due to its nature is very limited in its scope. Even using 4 bytes to hold each number, with 8 bits for the fractional part after the point, the largest number that can be held is just over 8 million. Another format is needed for holding very large numbers.

In decimal, very large numbers can be shown with a mantissa and an exponent. i.e. 0.12*10² Here the 0.12 is the mantissa and 10² is the exponent. the mantissa holds the main digits and the exponents define where the decimal point should be placed.

The same technique can be used for binary numbers. For example, two bytes could be split so that 10 bits are used for the mantissa and the remaining 6 for the exponent. This allows a much greater scope of numbers to be used.

Converting binary floating-point to decimal

1) Find the sign of the mantissa (write it down)

2) Write down the mantissa. If the mantissa is negative, convert the two's complement over it.

3) Find the exponent value. If the exponent is negative, convert the two's complement over it.

4) Move the floating-point in the mantissa to the distance that defines the exponent (point 3), left for negative exponent, right for positive.

5) Calculate the whole part and the fractional part. Put a sign (point 1)

Calculate the value of the number

Example 1. Mantissa is positive, Exponent is positive

The mantissa m = 0.1001001002

The exponent e = 0001002 = 410

Thefore the value is 0.1001001002 x 24 = 1001.0012 = 9.12510


Example 2. Mantissa is negative, Exponent is positive

The mantissa is a negative value. Converting the two's complement gives m = - 0.0110111002

The exponent e = 0001002 = 410

Thefore the value is - 0.0110111002 x 24 = - 110.1112 = - 6.87510


Example 3. Mantissa is positive, Exponent is negative

The mantissa is  m = 0.1010000002

The exponent is a negative value. Converting the two's complement gives e = - 0000102 = - 210

Thefore the value is 0.1012 x 2-2 = 0.001012 = 0.1562510


Example 4. Mantissa is negative, Exponent is negative

The mantissa is a negative value. Converting the two's complement gives  m = - 0.1010000002

The exponent is a negative value. Converting the two's complement gives e = - 0000102 = - 210

Thefore the value is - 0.1012 x 2-2 = 0.001012 = - 0.1562510

Floating Point Binary Converter


Questions:

Exercises:

Ex. 1

Ex. 2

Ex. 3

Exam questions:

Категория: Representing numbers | Добавил: bzfar77 (08.02.2021)
Просмотров: 5344 | Теги: exponent, mantissa, floating point number, Binary, fixed point number | Рейтинг: 4.9/7
Всего комментариев: 0
avatar