Convert a Bitstring into an integer value I have got a String filled up with 0 and 1 and would like to get an Integer out of it:

String bitString = ""; 
int Number;
int tmp;

bitString = "";
  for (i=1;i&lt;=10;i++)
  {
    tmp= analogRead (A0);
    bitString +=  tmp % 2;
    delay(50);
  }
// now bitString contains for example "10100110" 
// Number = bitstring to int &lt;-------------
// In the end I want that the variable Number contains the integer 166
If you only need the string for printing you can store value in an integer and then use the Serial.print(number,BIN) function to format the output as a binary value.  Appending integers to strings is a potentially costly operation both in performance and memory usage.

int Number = 0;
int tmp;

for (int i=9;i&gt;=0;i--) {
  tmp = analogRead (A0);
  Number += (tmp % 2) &lt;&lt; i;
  delay(50);
}
Serial.print(Number, BIN);