Created
September 6, 2014 19:08
-
-
Save maartentamboer/71448636da7f5f568d08 to your computer and use it in GitHub Desktop.
Decimal value to binary string
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 <string> | |
#include <stdint.h> | |
using namespace std; | |
int main(int argc, char **argv) | |
{ | |
uint32_t Dec = 1234; | |
uint32_t Comp = 1 << 31; | |
string BinStr; | |
for(int i = 0; i<=31; i++) | |
{ | |
if((Comp & Dec) != 0) | |
{ | |
BinStr.append("1"); | |
} | |
else | |
{ | |
BinStr.append("0"); | |
} | |
Comp >>= 1; | |
} | |
cout << BinStr << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment