Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mpurbo
Created March 11, 2013 07:33
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 mpurbo/5132544 to your computer and use it in GitHub Desktop.
Save mpurbo/5132544 to your computer and use it in GitHub Desktop.
Integer bits of double/float
#include <stdint.h>
uint64_t doubleToBits(double x) {
const union { double f; uint64_t i; } xUnion = { .f = x };
return xUnion.i;
}
uint32_t floatToBits(float x) {
const union { float f; uint32_t i; } xUnion = { .f = x };
return xUnion.i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment