To turn on bit 6 of x: x = x | 0x00000080 ; or, with fewer characters x |= 0x00000080 ; or, without having to figure out where the 6'th bit isor, x = x | (1<<6) ; To turn off bit 6 of x: x = x & 0xFFFFFF7F ; or, To turn off bit 6 without evening knowing the word size x = x & ~0x0080 ; or, with fewer character x &= & ~0x0080 ; or, without even knowing the word size! x = x & ~(1<<6) ; Turning on bits 6 to 11 x = x | 0x00000FC0 ; x |= 0x00000FC0 ; x = x | (0x3F<<6) ; Turning off bits 6 to 11 x = x & 0xFFFFF03F ; x = x & ~0x0FC0 ; x &= ~0x0FC0 ; x = x & ~(0x3F<<6) ; Turning on bits BS to BF x = x | ( ((1 << (BF - BS)) - 1) << BS) ; Turning off bits BS to BF x = x & ~( ((1 << (BF - BS)) - 1) << BS) ;