hi I have write a smaple code like this uint size =0; uchar aa = 0x15; uchar bb = 0x11; size = (((aa+1)*(bb+1))<<1); why size is 0x18 not 0x318?? How to get correct answer?? thanks a lot
Yes. The casts force the calculation to be done at int width (16 bits for Keil C51). The compiler option for automatic integer promotion would have done the same thing automatically. The ANSI C specification has rules for automatically "promoting" 8-bit values in this sort of calculation to integers. On an 8-bit processor, doing 16-bit math is less efficient and often unnecessary. So, C51 does not follow the integer promotion rules unless you ask it to do so. You can trade off slightly non-standard language behavior for higher efficiency. Or, you can insist on standard behavior if that is more important to you.