To set or clear a bit within a byte variable based upon a bit in the same or other byte variable try:
(byte2 &= ~BITMASK2), (byte1 & BITMASK1) ? (byte2 |= BITMASK2) : 0;
Which could be encapsulated into a macro:
#define setmask(b1, m1, b2, m2) (((b2) &= ~(m2)), ((b1) & (m1)) ? ((b2) |= (m2)) : 0)
which you would use thusly:
setmask(byte1, BITMASK1, byte2, BITMASK2);
The result for the PIC is:
bcf _byte2,3 btfsc _byte1,2 bsf _byte2,3
Which is very effecient. If you don't want to clear the bit first (e.g. if it was a port pin) then it would be:
(!(byte1 & BITMASK1) ? (byte2 &= ~BITMASK2) : 0), (byte1 & BITMASK1) ? (byte2 |= BITMASK2) : 0;
PIC - Bit operations@