Skip to content

Instantly share code, notes, and snippets.

@shouichi
Created September 17, 2013 08:24
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 shouichi/6591513 to your computer and use it in GitHub Desktop.
Save shouichi/6591513 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
typedef union {
unsigned int i;
float f;
} holder;
void printBits(int x)
{
int i;
unsigned int mask = 1 << 31;
for (i = 0; i < 32; i++) {
if (x & mask) {
printf("1");
}
else {
printf("0");
}
mask >>= 1;
}
printf("\n");
}
int main(void)
{
holder h;
h.f = 3.14;
printBits(h.i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment