Microchip XC8, strange sign warning

274 views Asked by At

I am using Microchip XC8 and am getting a bit confused. I have that code:

void fastBinaryToBCD(unsigned short int n, unsigned char mem){
// AppNote www.cypress.com/file/42131
unsigned char d4, d3, d2, d1, d0, q;    // d4-d0 - decimal numbers

d0 = n & 0xF;
d1 = (n>>4u) & 0xF;
d2 = (n>>8u) & 0xF;
d3 = (n>>12u) & 0xF;
d0 = 6u * (d3 + d2 + d1) + d0; //<------------warning
q = d0 / 10u;
d0 = d0 % 10u;
d1 = q + 9u*d3 + 5u*d2 + d1;
//...
}

I am getting a warning:

warning: (373) implicit signed to unsigned conversion

I recon that all literals are signed by default, so i put all the u's. It works everywhere, except for that line I pointed out. What also doesn't yield a non-warning result is:

d0 = (unsinged char)(6u * (d3 + d2 + d1) + d0);

The warning remains.

What's going on in this line? :D

Best regards!

1

There are 1 answers

0
Mike On

Sometines xc8 is a little bit tricky with warnings. The literal 0x0F is signed so please try:

d0 = n & 0xFu;
d1 = (n>>4u) & 0xFu;
d2 = (n>>8u) & 0xFu;
d3 = (n>>12u) & 0xFu;