On Sat, Aug 16, 2014 at 7:11 PM, peter green wrote: > The int size in the microchip compilers is 16 bit iirc. > > In c types smaller than int are supposed to be (though iirc at least C18 > had an option to not do this) are automatically promoted to int and your > constant is probablly also being treated as an int. > > So red * 0x100 is treated as (int)red * (int)0x100 which gives an int > with value 0xFF00. I'm not sure if C defines what should happen when a > smaller signed type is assigned to a larger unsigned type but it seems > C18 is sign extending it. > > 0x10000 works because it's too big to fit in an int. So it gets treated > as a long. That forces the multiplication to be treated as a > multiplication of a pair of longs producing a long result. Ah, this makes sense. I thought that defining the destination would cause the calculation to be cast correctly. > You need to add an explicit cast to force things to be done with the > type you want. e.g. > > redtemp =3D red * (uint32_t)0x100; Works like a charm! I wasn't aware I could cast like that, thank you! Josh --=20 A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. -Douglas Adams --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .