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
The time complexity of the given C++ program to convert a real value to IEEE 754 floating point representation is O(1) since it only performs a fixed number of operations regardless of the input value. The program consists of a few simple bitwise operations, union assignment, and function calls that execute in constant time.
The space complexity of the program is also O(1) because it uses a fixed amount of memory to store the union variable var.
Program 2: Convert a floating point representation to its real value
The float value of the given IEEE-754 representation is : -2.250000
Please Login to comment...