school/cs142/lab02/binary.cpp
2016-04-06 20:45:34 -07:00

58 lines
1.1 KiB
C++

#include <iostream>
#include <vector>
using namespace std;
int main() {
int value;
int first, second, third, fourth, fifth;
vector<int> final;
cout << "please insert your number between 0 and 31" << endl;
cin >> value;
int prin = value%2;
value = value/2;
if(prin >=1)
first = 1;
else
first = 0;
final.push_back(first);
prin = value%2;
value = value/2;
if(prin >=1)
second = 1;
else
second = 0;
final.push_back(second);
prin = value%2;
value = value/2;
if(prin >= 1)
third = 1;
else
third = 0;
final.push_back(third);
prin = value%2;
value = value/2;
if(prin >= 1)
fourth = 1;
else
fourth = 0;
final.push_back(fourth);
prin = value%2;
value = value/2;
if(prin >= 1)
fifth = 1;
else
fifth = 0;
final.push_back(fifth);
cout <<fifth<<fourth<<third<<second<<first << endl;
// for(unsigned int i = 0 ; i<final.size();i++) {
// cout << final[i];
// }
cout << "\n";
}