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

I. Fixed 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 fractions 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

Examples. Using one byte to hold each number, with an imaginary binary point fixed after the fourth digit, convert the following unsigned decimal numbers to binary.

5.7510 = 0101.11002

-4.37510 = 1011.10102

 

II. 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 computers to represent fractions but has a limited range. Even with 4 bytes (32 bits) and 8 bits for the fractional part, the largest representable number is just over 8 million. This limitation makes it unsuitable for very large numbers.

Floating-point notation overcomes this by using a mantissa (main digits) and an exponent (position of the decimal point), similar to scientific notation in decimal. For example, 0.12 × 10¹⁵ has 0.12 as the mantissa and 10¹⁵ as the exponent.

In binary, two bytes (16 bits) can be divided into 10 bits for the mantissa and 6 bits for the exponent, allowing a much wider range of numbers to be represented efficiently.

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

Therefore 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

Therefore 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

Therefore 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

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

Floating Point Binary Converter

Normalisation float point numbers

  • The normalised version of a positive fractional number has no leading zeros after the binary point — a normalised positive number always starts as 0.1;
Denary representation Floating-point binary representation
(mantissa exponent)
-0.25 * 24 1 110 0100
-0.5 * 23 1 100 0011
-1.0 * 22 1 000 0010
normalized
  • The normalised version of a negative fractional number has no leading ones after the binary point — a normalised negative number always starts as 1.0.
Denary representation Floating-point binary representation
(mantissa exponent)
0.125 * 24 0 001 0100
0.25 * 23 0 010 0011
0.5 * 22 0 100 0010
normalized

 


Questions:

Exercises:

Ex. 1

Ex. 2

Ex. 3

Exam questions:

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