Curuxa was an open-hardware modular electronics and robotics platform for teaching, developed by Adrián Bulnes (Urriellu) between 2009 and 2010. This is a frozen, read-only archive of the project’s website, curuxa.org; nothing here is maintained. Source code and designs: github.com/Urriellu/Curuxa · Original capture: Wayback Machine · urriellu.net

Snippet:Bitwise operations

From Curuxa

This is a collection of common operations done with individual bits in variables.

Set/clear bits

#include <pic16fxxx.h>
 
#define SetBit(v,bit) v |= (1 << bit);
#define ClearBit(v,bit) v &= ~(1 << bit);
 
// more things...
 
void main() {
    int a = 1;
    SetBit(a, 2);
    // now "a" is 5 (decimal), 00000101 (binary)
    ClearBit(a, 0);
    // now "a" is 4 (decimal), 00000100 (binary)
}