-----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of peter green Sent: Saturday, August 16, 2014 7:12 PM To: Microcontroller discussion list - Public. Subject: Re: [PIC] XC8 Math weirdness? Josh Koffman wrote: > greentemp =3D green * 0x10000; > redtemp =3D red * 0x100; > bluetemp =3D blue; > > The temp variables are all uint32_t, and the input values are all=20 > uint8_t. The goal is to shift the values over so I can then add them=20 > together. > > When I execute this code with all of the input values as 0xFF, things=20 > are weird. Green (*0x10000) and Blue (*1) work fine, I end up with > 0xFF0000 and 0xFF, respectively. However, redtemp ends up with=20 > 0xFFFFFF00, which I can't explain. > =20 I think Peter's response to this will get you going. However, it is worth noting that a shift is likely to be _much_ faster than a multiply (unless o= f course the compiler is smart enough to see that this multiply can be implemented by a shift): > greentemp =3D green << 16; > redtemp =3D red << 8; > bluetemp =3D blue; ~ Bob Ammerman RAm Systems --=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 .