Created
August 15, 2013 01:25
-
-
Save hz9xa/6237443 to your computer and use it in GitHub Desktop.
Floating Point to Binary Value(C++)
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> | |
#include <bitset> | |
int main() | |
{ | |
union | |
{ | |
float input; // assumes sizeof(float) == sizeof(int) | |
int output; | |
} data; | |
data.input = 2.25125; | |
std::bitset<sizeof(float) * CHAR_BIT> bits(data.output); | |
std::cout << bits << std::endl; | |
// or | |
std::cout << "BIT 4: " << bits[4] << std::endl; | |
std::cout << "BIT 7: " << bits[7] << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment