algoritm goes wrong

void loop()
{

  int i;
  int k,q,w,e,r;
  int l[100];
  if(Serial.available())
  
  {char z;
  

      z= Serial.read();
   
     while (z > 9) {
       for(i=0;i<4;i++){
    
      l[i] = z % 10;
         Serial.print(l[i]);
         
        z /= 10;

would expect that this will split my 4 digit number … but it just prints some random values
i can’t see why …

z is a signed character so the value can't be higher than 127.

Your sketch is incomplete.

Looks like it should print out the decimal character code for each character received, backward.

ok

got it

thank you

If you are reading characters then you need something like this

char z = Serial.read() ;
if ( z >= ‘0’&& z <= ‘9’)
{
int k = z-‘0’; // k is the numerical value of your digit
}
else // z is not a char representing a digit in the range ‘0’ to ‘9’
{
// do something else
}

If you are reading characters then you need something like this

Except that creating a local variable (k) that immediately goes out of scope is pointless.

PaulS: Except that creating a local variable (k) that immediately goes out of scope is pointless.

Well, yes - there's sme adittional code that needs to be put there.

OP: you need to grok the fact that things coming in on the serial are ASCII codes. A letter 'A' is 65. A digit '2' is 50. If you want to treat characters coming in as numbers encoded as strings of characters, then there's programming to be done.