Go Down

Topic: bitToggle() (Read 1 time) previous topic - next topic


I noticed when working on my current project that there's nice defines for setting and clearing a bit, but none for toggling a bit.  I think this #define based on the others would do the job, but I haven't tested it:

Code: [Select]
#define bitToggle(value, bit) ((value) ^= (1UL << (bit)))


you should write a test program for it ;)  - it looks ok.

if you are interested in bithacks check - http://graphics.stanford.edu/~seander/bithacks.html
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


These are my defines:

Code: [Select]

#define SetB(PORT, BIT) ((PORT) |= 1<< (BIT))
#define ClrB(PORT, BIT) ((PORT) &= 1<< (BIT))
#define TogB(PORT, BIT) ((PORT) ^= 1<< (BIT))
#define TestB(PORT, BIT) ((PORT) & (1<<BIT))

Not compatible with Arduino Pin numbers.
This... is a hobby.

Go Up