 # 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; } ```

Checking the Number is Armstrong or Not - To check whether a number is an 'Armstrong' number or not an Armstrong number in 'C++' Language, 'enter the number', now check for the Armstrong number, whether the entered

A destructor is a Special Member Function - In C++, Name should begin with tilde sign(~) and must match class name. There cannot be more than one "Destructor" in a class. Unlike "constructors" that can have parameters, and

Check Whether the Number is Armstrong - This C Program code checks whether a given number is armstrong number. An Armstrong number is an n-digit base b number such that the Sum of its Digits raised to the Power N is

C coding Basic binary search tree routines - Insert, swap, search value, search minimum and search maximum values. Destroy, count tree nodes. Insert a tnode into the binary tree. Traverse the tree to get a pointer to the

Convert Strings to UpperCase use Pointers - C program to 'convert string' from Lowercase to uppercase string using loop. All characters are represented as an integer value known as "ASCII" value. Where A is represented with 65

C Language Sample Add Two Polynomials - Enrter the elements of the first poly. Unable to create memory. Enter the elements of the second poly. Printing the elements of the lists. The elements of the poly first are. The...

C++ Programs Converts Decimal to Binary - To convert decimal number to binary number in C++, you have to enter the decimal number to convert it into 'binary number' to print the equivalent value in binary format as shown in

C Language program code to Divide Array - To divide an array into two, we need at least three array variables. We shall take an array with continuous numbers and then shall store the values of it into two different variables...