Concatenate numbers in CCs

I have the following problem with CCS compiler for pic. The function concatenates numbers, but only works with single digit numbers for example the 1 with the 5 shows me 15.

Well, now if I do the 21 with the 56 for example it gives me a wrong number. What can it be? PS: when I test it with a C compiler it works for me.

int concat(int x, int y)
{
    int temp = y;
    while (y != 0)
    {
        x = x * 10;
        y = y / 10;
    }
    return x + temp;
}

int x = 2;
int y = 4;
aux = concat(x, y);
printf(lcd_putc, "%u", aux);
 2
Author: Eugenio Liberatori Svoger, 2016-07-28

1 answers

In CCS PICC the type " int " is 8 bits. Since you are handling numbers larger than 255 you should use a larger type like"int16".

 2
Author: JLP, 2017-12-07 13:52:10