#include <iostream> #include <string> using namespace std; //整数十进制转二进制 string DecimalToBinary(int dec) { string returnStr = ""; while (dec) { if (dec & 0x01 == 1){ returnStr.insert(0, "1"); dec >>= 1; } else{ returnStr.insert(0, "0"); dec >>= 1; } } return returnStr; } int main() { int a = 1024; string str = DecimalToBinary(a); cout<<a<<endl; cout<<str<<endl; return 0; }
EOF