Fundamentals of data representation Year 2
Table of Contents
1 Representing Numbers Year 2
Representing Numbers with a Fractional Part
- We have learned the following methods of representing numbers:
- unsinged integer
- signed integer
- two's compliment for signed integers
- fix point representation of fraction numbers.
- We have also learned that with fixed number of bits, there are always numbers that cannot be represented accurately. For example, the number 0.1 cannot be represented in binary exactly.
Representing Numbers with a Fractional Part - FPF
- FPF (Floating Point Form) is a way of representing numbers that increases the precision and the range of numbers for given number of bits.
- Using the scientific notation (normalised form) to represent large numbers so they are easy to read. For example:
Decimal Value Noramlised As Mantissa Exponent 2100 ---> 2.1 x 103 2.1 3 5500000 ---> 5.5 x 106 5.5 6
- To represent numbers in binary using the scientific/normalised form, we allocate certain number of bits for the Mantissa and certain number of bits for the exponent. Throughout this notes, we will use 8 bits for Mantissa and 5 bits for exponent.
- Some examples of normalisation of binary numbers:
Binary Value Normalized As Exponent 1101.101 1.101101 3 .00101 1.01 -3 1.0001 1.0001 0 10000011.0 1.0000011 7
- To workout the FPF of a decimal number using 2's complement:
- Using 67 as an example, convert the decimal number to binary using 2's complement.
67 in binary (2's complement): 0 100 0011. ----- the first bit is the sign bit. The point is for later normalisation convenience normalise by moving the point to the place indicated below: 0.100 0011 ----- the point is imaginary only. The number of places the point moved is the exponent: 7 7 in binary using 5-bit pattern: 00111 The final answer is: 01000011 00111
- Using 6.75 as an example, convert the decimal number to binary using 2's complement.
6.75 in binary (2's complement): 0 110.1100 ----- the first bit is the sign bit.Two more 0s padded to the end o make the 8 bits Mantissa. Normalise by moving the point to the place indicated below: 0.110 1100 The number of places the point moved is the exponent: 3 3 in binary using 5-bit pattern: 00011 The final answer is: 01101100 00011
- Now, lets try negative number, -6.75 as an example, convert the decimal number to binary using 2's complement.
-6.75 in binary (2's complement): 1. 6.75 in binary using the 7 bits (leave the sign bit for now): 110.1100 ----- Two more 0s padded to the end o make the 8 bits Mantissa. 2. add 1 and then flip: 001.0100 3. add the sign bit back: 1001.0100 Normalise by moving the point to the place indicated below: 1.001 0100 The number of places the point moved is the exponent: 3 3 in binary using 5-bit pattern: 00011 The final answer is: 10010100 00011
- Using 67 as an example, convert the decimal number to binary using 2's complement.
Converting FPF to Decimal Numbers
- All numbers are using 2's complement, 8-bit Mantissa and 5-bit exponent
- DO NOT forget the invisible decimal point after the first sign bit
- 01100001 00110
- A negative FPF: 10110001 00101
- A negative FPF with negative exponent: 10110000 11101
Try It
All binary numbers are in 2's complement normalised floating point representation. 8 bits for Mantissa and 5 bits for exponent
- Convert the following to decimal numbers:
- Convert the following decimal numbers to binary numbers:
- 12.75
- 1344
- -0.0125
- The smallest positive number can be represented using 8 bits for mantissa and 5 bits for exponent.
- The smallest number can be represented using 8 bits for mantissa and 5 bits for exponent.
- The largest number can be represented using 8 bits for mantissa and 5 bits for exponent.
Rounding Errors
- Using limited/fixed number of bits, there are always numbers that cannot be represented accurately. For example, representing 0.5 can be accurate, but representing 1/3 cannot be.
- The following image illustrates the limitations using
8 bits signed,fixed point
representation. - To represent the number
0.51
, the closest we can get is: 0.5 + 0.0078125 = 0.5078125 - Rounding errors:
Absolute and Relative Errors
Use the above example, to calculate the errors as a result of the not-so-accurately represented number using limited number of bits:
absolute error
= 0.51 - 0.5078125 = 0.0021875relative error
= absolute error/0.51 = 0.0021875/0.51 = 0.00428922 or 0.428922%
Range and Precision
- We have learned representing numbers using
fixed point
andfloating point
scheme. Here are the pros and cons of those two schemes in terms of range and precision:- Using the number of bits,
FPF
allows greater range of numbers which means from smaller number to larger number. Larger Mantissa, better precision, larger exponent, greater range. Fixed point
is simpler, therefore faster to process.Fixed point
can have varies range and precisions depending on how many points before and after the point. More bits before the point, the greater the range, more bits after the point, the greater precision.
- Using the number of bits,
Normalisation of Floating Point Form
See above on FPF and normalisation
Underflow and Overflow
Underflow
is when a number is too small to be represented in the given number of bits. This can happen when a small number is divided by a number that is larger than 1, this may be represented by 0.Overflow
is when a number is too large to be represented in the given number of bits. For example, the product of two larger than 1 numbers.
Try It
- Convert the following binary numbers to hex and show your working. Check them by using the table.
- 11110011
- 00101100
- 10101010