// Setting a bit: number |= 1 << n; // Clearing a bit number &= ~(1 << n); // Toggling a bit number ^= 1 << n; // Checking a bit bit = (number >> n) & 1; // Changing the nth bit to x number = (number & ~(1 << n)) | (x << n);