Created
April 9, 2015 00:31
-
-
Save snoopspy/328ec3b5a6a70f06c6c5 to your computer and use it in GitHub Desktop.
float to int
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 <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