#include
#include
using namespace std;
void line() { cout << setw(12) << setfill('-') << endl;}
int main() {
int binary[8];
int num;
int bits[8] = {128,64,32,16,8,4,2,1};
do {
line();
cout << "write in the number to be converted into binary." << endl;
cin >> num;
for(int i = 0;i < 8;i++) {
if(num >= bits[i]){
binary[i] = true;
num = num - bits[i];
}
else if(num < bits[i]) {
binary[i] = false;
}
}
for(int i = 0;i < 8;i++) {
cout << binary[i] ;
}
}while (1);
system("pause");
return 0;
}
this code is made about 1 month ago,and this is supposed to convert numbers into binary. Since I'm a beginner,the code might be messy and unintelligent. Please tell me how to improve this or to make it more efficient. If by any chance I'm in the wrong section, forgive me,this is the first time visiting this site.