Serial.parseint() - How to parse individual digits to ints?

Hey,

this is only about making an already working code cleaner.

So far, I send a multiple-digit number to the Arduino via the Serial monitor. Then, I use Serial.parseint() to store the whole number in an int. Next, using division and modulo, I isolate the individual digits and store them in separate ints (to perform further math on them).

I am wondering if it would be possible to parse the individual digits of the incoming number to ints directly. The gain from this would be that the coding and computation effort for dismantling the number into digits could be saved.

Many thanks in advance!

Edit: Also, I imagine that there could be some speed gains from this. If the incoming number and subsequently the divisors for isolating the digits become really long, the divisions could take their time on the comparatively weak arduino, right?

Related question: If the arduino does 8-bit math, I understand that for values bigger than 8 bit, the arduino has to split mathematical operations up into several steps. How does the arduino "remember" the outcome of the first step, which is needed for the subsequent steps? I assume it must be saved somewhere? Where would that be?

Just read digits into an array of chars instead. You will need to know when all digits have arrived. Either send a LF to tell you the number's over or do a timeout using millis. Or both.

Many thanks for your answer!

Where can I find more information on this? I am a beginner and do not know what Char arrays are exactly or how to use them, also I did not understand the part about the LF (?) and timeout.

In the ASCII code, digits are consecutive and in order.

To read a character:

   int character = Serial.read();

(You get a value of -1 if the input buffer is empty.)

To check that a character is a digit:

  if (character >= '0' && character <= '9')

To convert an ASCII digit to its numeric value:

  int value = character - '0';