Created
November 17, 2015 13:31
-
-
Save pascal-mueller/c9e7872f44b4396474ab to your computer and use it in GitHub Desktop.
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 <typeinfo> | |
unsigned int dec2bin(unsigned int n) { | |
//Calculate and output | |
int k = 2; | |
std::cout << "Reverse binary representation is: "; | |
std::cout << n%2; | |
while(n%k != n) { | |
if(n%k != n%(k*2)) | |
std::cout << 1; | |
else | |
std::cout << 0; | |
k = k*2; | |
} | |
return 0; | |
} | |
} | |
int main() { | |
//unsigned int dec; | |
unsigned int foo = 0; | |
std::cin >> std::hex >>foo; | |
//std::cout << foo; | |
dec2bin(foo); | |
//c2bin(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment