unsigned integers variables can be subtracted more than they contain - if I understand correctly the question.
u_int16_t u = 10;
u -= 20; // => u = u - 20;
printf("%x, %u\n", u, u); // => fff6, 65526
The difference is
- when displayed, u does not show a negative value - ie the MSb (most significant bit, ie bit 15) is interpreted (here) as 215, the next as 214 etc...
- when extended (eg to 32 bits) the MBb is not propagated from bit 16 to bit 31 (as they would be if signed) - they're
0
- when right shifted the value MSb is always
0
(would be the same as previous MSb if signed, e.g1
for a negative value)
So your mapping will keep working with u_int16_t
(and you don't need the %
modulo 65536 if you work with that type everywhere since anyway the values are on 16 bits - the modulo is implicit).