//************************************** // Name: Binary read // Description:This code takes a string of ones and zeros and converts them into an integer. // By: Mike Smith // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //************************************** #include <cstdio> #include <iostream> #include <string> using namespace std; int binaryToInt(string binary) { int number = 0; for(unsigned char c: binary) { number<<=1; number|=c-'0'; } return number; } int main (void) { string binary = "101"; int number = binaryToInt(binary); cout << binary << " is " << number << endl; }