Have you considered using a union for that: union { uint32_t rgb_32; struct { uint8_t red:8; uint8_t green:8; unit8_t blue:8; }col; }rgb; This way you can access the 32 bit value with rgb.rgb_32 and, for example red with rgb.col.red for both reading and writing. You can still use the shift/multiply methods with rgb.rgb_32 (but you need to know how the bitfields are ordered by the compiler). The union means that the variables within it shares the same memory (rgb_32 and col in this case). /Ruben > Hi all, >=20 > Plugging away at my LED project. I'm currently trying to combine 3 > separate 8 bit values into one 24 bit value (stored in a 32 bit > variable), and I've come across some weirdness. >=20 > As part of my function, I've broken things down farther than I usually > would to help isolate the problem. I now have this code: >=20 > greentemp =3D green * 0x10000; > redtemp =3D red * 0x100; > bluetemp =3D blue; >=20 > The temp variables are all uint32_t, and the input values are all > uint8_t. The goal is to shift the values over so I can then add them > together. >=20 > When I execute this code with all of the input values as 0xFF, things > are weird. Green (*0x10000) and Blue (*1) work fine, I end up with > 0xFF0000 and 0xFF, respectively. However, redtemp ends up with > 0xFFFFFF00, which I can't explain. >=20 > Changing the red multiplier to 0x10000 (just as a test) works. > Changing it to 0x1 works as well. But...0x100 doesn't. >=20 > I know I'm probably missing something simple here, but I can't seem to > figure it out. >=20 > Help! >=20 > 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 >=20 >=20 > ----- > No virus found in this message. > Checked by AVG - www.avg.com > Version: 2014.0.4745 / Virus Database: 4007/8050 - Release Date: 08/17/14 >=20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D Ruben J=F6nsson AB Liros Electronic Box 9124, 200 39 Malm=F6, Sweden TEL INT +46 40142078 FAX INT +46 40947388 ruben@pp.sbbs.se =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D --=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 .