-
-
Save tsahara/5562991 to your computer and use it in GitHub Desktop.
bit representation of ieee 754 floating point numbers
This file contains 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> | |
int | |
main(int argc, char **argv) | |
{ | |
float f; | |
unsigned int i, mask; | |
f = 1.5; | |
i = *(unsigned int *)(void *)&f; | |
for (mask = 1 << 31; mask > 0; mask >>= 1) { | |
putchar((i & mask) ? '1' : '0'); | |
if (mask == 1 << 31 || mask == 1 << 23) | |
putchar(' '); | |
} | |
puts(""); | |
i = 0xffffffff; | |
f = *(float *)(void *)&i; | |
printf("0x%x = %g\n", i, f); | |
} |
Author
tsahara
commented
May 12, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment