please dont rip this site

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@

See also:


file: /Techref/language/ccpp/bittwid.htm, 1KB, , updated: 2008/3/19 01:23, local time: 2014/11/23 18:25,
TOP NEW HELP FIND: 
54.166.116.36:LOG IN

 ©2014 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE! / 

<A HREF="http://www.massmind.org/techref/language/ccpp/bittwid.htm"> Efficient bit twiddeling in C</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to www.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .