I wanted to post this on the Arduino forum but couldn't find any "new post" button...
Anyway, I wrote this function to convert a binary string into an int/long.
However, it doesn't always work with big numbers.
The following code is supposed to return "888888" but returns "888.887"
void setup() {
Serial.begin(9600);
String data = "11011001000000111000"; //888888
Serial.print(binStringToInt(data));
}
unsigned long binStringToInt(String bin) {
unsigned long total = 0;
int binIndex = 0;
for (int i = bin.length() - 1; i > - 1; i--) {
total += round(pow(2, binIndex)) * (bin.charAt(i) - '0');
binIndex++;
}
return total;
}
pow(2, binIndex). Use1 << binIndexinstead