Skip to content

Instantly share code, notes, and snippets.

@snoopspy
Created April 9, 2015 00:31
Show Gist options
  • Save snoopspy/328ec3b5a6a70f06c6c5 to your computer and use it in GitHub Desktop.
Save snoopspy/328ec3b5a6a70f06c6c5 to your computer and use it in GitHub Desktop.
float to int
#include <iostream>
int main()
{
{
// float to int
float f = 1;
int i = *((int*)&f);
std::cout << i << std::endl;
}
{
// int to float
int i = 0b11111111111111111111111111111111;
float f = *((float*)&i);
std::cout << f << std::endl;
}
}
/*
result
1065353216
-nan
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment