I'm trying to write a program that converts binary to base10 using a user inputted binary number
This is the original 'inefficient' code:
void BASE10() {
int col_0, col_1, col_2, col_3, col_4, col_5, col_6, col_7;
cout << "Please enter the Binary number you would like to convert ONE digit at a time" << endl;
cin >> col_0;
cin >> col_1;
cin >> col_2;
cin >> col_3;
cin >> col_4;
cin >> col_5;
cin >> col_6;
cin >> col_7;
int num = 0;
if (col_0 == 1) {
num = num +128;
}
if (col_1 == 1) {
num = num +64;
}
if (col_2 == 1) {
num = num +32;
}
if (col_3 == 1) {
num = num +16;
}
if (col_4 == 1) {
num = num +8;
}
if (col_5 == 1) {
num = num +4;
}
if (col_6 == 1) {
num = num +2;
}
if (col_7 == 1) {
num = num +1;
}
cout << num << endl;
Restart();
Instead of this I want to use a for loop to pass a single string, the user inputs into an array of integers which can then be used in the calculation.
How do I do this?
std::bitset