Skip to content

Instantly share code, notes, and snippets.

@pascal-mueller
Created November 17, 2015 13:31
Show Gist options
  • Save pascal-mueller/c9e7872f44b4396474ab to your computer and use it in GitHub Desktop.
Save pascal-mueller/c9e7872f44b4396474ab to your computer and use it in GitHub Desktop.
#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