We have an assignment in class to convert from Decimal to single precision using c and I'm completely lost.
This is the assignment:
The last part of this lab involves coding a short c algorithm. Every student must create a program that gets a scientific notation floating point number as an input and prints it´s IEE754 single precission value both in binary and hexadecimal.
The ouput of the program must be equal to the following : “Introduce a float point number in decimal (scientific notation): The decimal float 1.234500e-04 is 3901725B in hexadecimal (IEEE 754). “
The #includes we have learnt so far are: stdio.h, math.h and string.h, so I don't think we are allowed to use any other includes. Also we havnt learned struct or union or any of that yet, because I saw those in other examples and I didn't understand anything.
I would really appreciate it if someone can guide me through making this code!
As OP only requested a guide:
Research
scanf()and the"%f"specifierResearch type punning a
floatintouint32_t. Review Could copy unsigned int bit values as float but float value not returned to the caller function correctly and avoid pointer tricks. See What is the strict aliasing rule?Research
printf()and the"%x"specifier.There a many ways to Is there a printf converter to print in binary format?.
Some are very general (base, 2,3,10,16,36...)