Split integer

Hi,

Is there a way to split the value of an integer over three new integers?
For example;
int i = 109 => int k = 1, int l =0, int m=9;

Thanks

i = 129;
j = i / 100; // so j = 1
k = (i / 10) - (j10) // so k = 2
l = i - j
100 - k*10 // so l = 9

It's a lot easer to split it up into binary parts.

Alternately convert the value into a string. Pars the string into separate numbers and convert back into a number.

Thnx Mike,
The formula will help.

What do you mean with it is easier to split it up in binary parts?
I have learned some binary math but that is a long time ago.

Cheers
Erik

Hi Erik and Mike,

I think mike means that it would be easier extracting the digits if you wanted these in base 2 instead of base 10.

FWIW, here is a routine that puts the digits into an array that could be useful if you need to handle numbers with lots of digits. Make sure the array size is at least as large as the max number of digits

int n = 109; // a number to test

int i=0;
char digits[3]; // if your maximum number has more than 3 digits, increase this accordingly

while(n>0 && i < 3){
digits[i++] = n % 10; // you can change the 10 here and below to any number base
n /= 10;
}
while(i>0)
Serial.print(digits[--i],DEC);