If you want to set both bits, only the OR operand is needed. If you want to clear the bits, only the AND operator is needed. If the target bits may be going either way, then you're right on track with your examples. On 3/12/15, Josh Koffman wrote: > Hi all, > > I've seen a few different ways to do this, and I'm not sure if there > are better or worse ways on this one. I am working in XC8, and I want > to be able to set multiple bits in a register at once. In assembly, > I'd mask off the bits I wanted to effect with an AND, then OR in my > desired value. > > For example, if I had a register called target, and I wanted to modify > bits 2 and 3, I'd first AND target with b'11110011', then take the > data I wanted to put in there (in this case b'11'), and OR target with > b'00001100'. > > Can I combine these commands in C? Or is there a better way? I think I co= uld > do: > > target |=3D 0b11110011; > target &=3D 0b00001100; > > But what about: > > target =3D (target | 0b11110011) & 0b00001100; > > Thanks! > > Josh > -- > A common mistake that people make when trying to design something > completely foolproof is to underestimate the ingenuity of complete > fools. > -Douglas Adams > -- > 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 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .