Bit manipulation - MarekBykowski/readme GitHub Wiki

HOME » Bit manipulation

Set/clear bit

#define NTH_BIT 4                                                              
                                                                               
unsigned int addr = 0xffffffff;                                        
enum flags { clear, set };                                             
                                                                               
addr &= ~(1<<NTH_BIT);                                                 
printf("mb: clearing %dth bit %x results in %x\n", NTH_BIT, 0xffffffff, addr); 
                                                                               
addr |= (1<<NTH_BIT);                                                  
printf("mb: setting %dth bit in %x = %x\n", NTH_BIT, 0xffffffff, addr);