Program for conversion of 32 Bits Single Precision IEEE 754 Floating Point Representation
Pre-Requisite: IEEE Standard 754 Floating Point Numbers
Write a program to find out the 32 Bits Single Precision IEEE 754 Floating-Point representation of a given real value and vice versa.
Input: real number = 16.75 Output: 0 | 10000011 | 00001100000000000000000 Input: floating point number = 0 | 10000011 | 00001100000000000000000 Output: 16.75
This implementation is based on Union Datatype in C and using the concept of Bit Fields.
Bit Fields are assigned when we don’t require the full memory that is usually allocated to some variables but we want to limit the amount of memory taken up by those variables. In C, members of a Union share the common memory space and taken we can access the members only one at a time.
Below is the implementation of the above approach:
Program 1: Convert a real value to its floating point representation
IEEE 754 representation of -2.250000 is : 1 | 10000000 | 00100000000000000000000
Program 2: Convert a floating point representation to its real value
The float value of the given IEEE-754 representation is : -2.250000