-
-
Save luisfergromo/de958018cce6702bcfbb5c56dd208af2 to your computer and use it in GitHub Desktop.
Converting floating-point number to IEEE754 representation by using union and struct in c.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| /* | |
| * See also : http://class.ece.iastate.edu/arun/CprE281_F05/ieee754/ie5.html | |
| */ | |
| union FloatingPointIEEE754 { | |
| struct { | |
| unsigned int mantissa : 23; | |
| unsigned int exponent : 8; | |
| unsigned int sign : 1; | |
| } raw; | |
| float f; | |
| } number; | |
| int main() { | |
| number.f = -6.8; | |
| printf("%x, %x, %x", number.raw.mantissa, number.raw.exponent, number.raw.sign ); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment