Binary String to base ten int

I have a String containing 1s and 0s (e.g String str = "01001100";). I would like to convert that to a base 10 int. I know in standard java I could use (x = Integer.parseInt(str, 2)) but I don't have access to the Integer class in the Arduino language. How could I do this in Arduino.

Thank you so much, All help is appreciated.

Convert it to a char array, and calculate it yourself.

{ '0',  '1', '0', '0', '1', '1, '0', '0', '\0'}

Subtract '0' from each element to get the decimal value. Start with a total of 0, and loop through each element, adding the decimal value for the element to your total. Left shift the total by 1 before moving to the next element.

sscanf() might also work.

You can try this program:

void setup()
{
  Serial.begin(9600);
}

int strbin_to_int(char* strbin) {
   int number;
   for (int i=0; i<8; i++) {
      number = (number << 1) + (*(strbin+i)-'0');
   }
   return number;
}

void int_to_strbin (int number, char* strbin) {   
   for (int i=0; i<8; i++) {
      *(strbin++) = ((number<<i) & 0x80) ? '1' : '0';
   }
   *strbin = '\0';   
}

void loop() {
  byte original;
  byte result;
  char strbin[9];
  
  if (Serial.available()) {
    original = Serial.read() - '0';
    
    Serial.print ("Original \"decimal\" number: ");
    Serial.println (original);
    
    int_to_strbin (original, strbin);
    Serial.print ("Binary: ");
    Serial.println (strbin);
    
    result = strbin_to_int(strbin);    
    Serial.print ("Result: ");
    Serial.println (result);
  }
}

The function int strbin_to_int(char* strbin) do this job. You have a little program that make the test of the function too, and other function to make the conversion "in the other direction".
Note that the example program only accept number of 1 digit.

There are strtoul and strtol

void setup() {

  String s = "11110000";
  
  int i = strtol( s.c_str(), NULL, 2 );
  
  Serial.begin( 9600 );
  Serial.print( i, DEC );
}

void loop() {}

Thank you guys so much I was able to use your suggestions to make it work.

Thanks for the help.