// For: https://forum.arduino.cc/t/toint-bug-how-unfortunate/1041669
//
// toInt reference:
// https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/toint/
// It returns a 'long', that is a signed long, 32 bits on a Arduino Uno
//
// If the return value of toInt is converted from long to unsigned long,
// it returns the right bits. That is awkward.
void setup()
{
Serial.begin(115200);
unsigned long a = 0xFFFFFFFF;
Serial.print( "a = ");
Serial.print( a); // print as decimal
Serial.print( " = 0x");
Serial.println( a, HEX); // print as hexadecimal
String s = String(a); // use as decimal number
Serial.println( "s = \"" + s + "\"");
long b = s.toInt(); // convert to binary
Serial.print( "b = ");
Serial.println( b);
unsigned long c = (unsigned long) s.toInt(); // use it as unsigned
Serial.print( "c = ");
Serial.println( c);
}
void loop() {}