How would I set xth bit in a int j?
All i can think of is something like this:
#define FIRST 0x00000001
#define SECOND 0x00000010
#define THIRD 0x00000100
#define FOURTH 0x00001000
#define BIT_TO_SET 4
int j = 0;
switch ( BIT_TO_SET ) {
case 1: j |= FIRST;
break;
case 2: j |= SECOND;
break;
case 3: j |= THIRD;
break;
case 4: j |= FOURTH;
case etc...
}
Is there a better or more effiecent way to set individual bits based on a int? This is for a PIC so every cycle counts and what I've got just seems a little clunky.
Cheers