You can use a simpler function to achieve that:
long binary_to_int(char *binary_string){
long total = 0;
while (*binary_string)
{
total *= 2;
if (*binary_string++ == '1') total += 1;
}
return total;
}
void setup(){
Serial.begin(9600);
String data = "11011001000000111000";
Serial.print(binary_to_int(data.c_str())); // prints 888888
}
I used.c_str()
to get a char *
to Arduino String.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…