C Programming Code Examples C > Bitwise Operators Code Examples C program to clear nth bit of a number C program to clear nth bit of a number Write a C program to input any number from user and clear the nth bit of the given number using bitwise operator. How to clear nth bit of a given number using bitwise operator in C programming. How to unset (0) the value of nth bit of a given number in C. To clear nth bit of a number we will use combination of bitwise left shift <<, bitwise complement ~ and bitwise AND & operator. Input number and nth bit position to clear from user. Store it in some variable say j and n. Left shift 1, n times i.e. 1 << n. Perform bitwise complement with the above result. So that the nth bit becomes unset and rest of bit becomes set i.e. ~ (1 << n). Finally, perform bitwise AND operation with the above result and j. The above three steps together can be written as j & (~ (1 << n)); #include <stdio.h> int main() { int j, n, newj; /* Input number from user */ printf("Enter any number: "); scanf("%d", &j); /* Input bit number you want to clear */ printf("Enter nth bit to clear (0-31): "); scanf("%d", &n); /* * Left shifts 1 to n times * Perform complement of above * finally perform bitwise AND with j and result of above */ newj = j & (~(1 << n)); printf("Bit cleared successfully.\n\n"); printf("Number before clearing %d bit: %d (in decimal)\n", n, j); printf("Number after clearing %d bit: %d (in decimal)\n", n, newj); return 0; }