Josh, Let's say you want to copy A into B and replace some of the bits in B with = bits from C ( defined by mask bitmask_C ) You can simply do that by following. B =3D A B ^=3D ( B ^ C ) & bitmask_C // xor B and C, mask the bits that need to be = copied and xor result back into B You can scale / use same procedure to copy groups of bits from few more sou= rces B ^=3D ( B ^ X ) & bitmask_X // yet another sets of bits from X copied into= B Dmitriy. -------------------------------------------- On Thu, 3/12/15, Josh Koffman wrote: Subject: Re: [PIC] Setting Multiple Bits in C To: "Microcontroller discussion list - Public." Date: Thursday, March 12, 2015, 11:17 AM =20 On Thu, Mar 12, 2015 at 6:34 AM, cdb wrote: > On Wed, 11 Mar 2015 23:16:45 -0400, Josh Koffman wrote: > :: 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. > > I normally try different ways with a new compiler/build and check the > assembler to see which gives the closest to an assembler instruction. > > Is this what you are wanting to do? > > OPTION_REG=3D(1< > Note the first two set to '1' the last keeps it as '0' =20 Hi Colin, =20 I goofed when I first asked the question. I should have stated I was trying to merge some data into a register, not specifically set or clear bits. =20 However, I do have an adjunct question. When performing an operation like you mentioned above, what happens to the bits that aren't specifically called out? Is that type of operation compiled such that it executes as something that leaves the existing bits alone? =20 Thanks! =20 Josh --=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 .