String text ="";
int base = 2; // base of number system of textstring
unsigned long binaryTexttoDecimal(String BinaryText);
void setup() {
Serial.begin(9600);
text ="1111000";
Serial.println(text);
Serial.println(binaryTexttoDecimal(text));
Serial.println(binaryTexttoDecimal(text),BIN);
//Serial.println(BinCharToInt('1'));
//Serial.println(BinCharToInt('0'));
//Serial.println(binaryTexttoDecimal("10001"),BIN);
//text = String(1011011);
text = String(1111);
Serial.println(text);
Serial.println(binaryTexttoDecimal(text));
Serial.println(binaryTexttoDecimal(text),BIN);
}
void loop() {
// put your main code here, to run repeatedly:
}
unsigned long binaryTexttoDecimal(String BinaryText)
{
int textSize = BinaryText.length();
double value = 0;
long int ValueB = 0;
for(int i=0; i<textSize; i++)
{
value += BinCharToInt(BinaryText.charAt(textSize-i-1))*pow(2,i) ;
ValueB = ValueB*base + BinCharToInt(BinaryText.charAt(i));
Serial.println(ValueB);
}
//return round(value);
return ValueB;
}
int BinCharToInt(char BinaryChar)
{
if(BinaryChar == '1')
return 1;
else
return 0;
}