Skip to content

Instantly share code, notes, and snippets.

@tsahara
Last active December 17, 2015 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsahara/5562991 to your computer and use it in GitHub Desktop.
Save tsahara/5562991 to your computer and use it in GitHub Desktop.
bit representation of ieee 754 floating point numbers
#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);
}
@tsahara
Copy link
Author

tsahara commented May 12, 2013

0 01111111 10000000000000000000000
0xffffffff = nan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment