Last active
August 29, 2015 14:09
-
-
Save dptole/dd4a9a73d6cfb0068c37 to your computer and use it in GitHub Desktop.
Takes a floating point number and show its binary representation.
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 <stdio.h> | |
using namespace std; | |
void printDouble(double d) { | |
unsigned long long i = *(unsigned long long *) &d; | |
for(int j = 63; j >= 0; j--) { | |
cout << ((i >> j) & 1); | |
if(j == 63) cout << " "; | |
else if(j == 52) cout << " "; | |
} | |
cout << endl; | |
} | |
int main() { | |
cout << "Give me a floating point number and I'll show you its binary representation." << endl; | |
double d = 0; | |
scanf("%lf", &d); | |
printDouble(d); | |
return 1; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment