Bitwise Operators Programming Exercise Sample Ques ons
1. Bitwise AND Operator: Write a C program to take two integers as input and perform a bitwise AND
opera on on them. Display the result in binary.
2. Bitwise OR Operator: Create a C program that reads two integers and performs a bitwise OR
opera on on them. Display the result in binary.
3. Bitwise XOR Operator: Write a C program that accepts two integers and uses the bitwise XOR
operator to find their XOR value. Display the result in binary.
4. Bitwise Le Shi : Develop a C program that takes an integer and shi s its bits to the le by a
specified number of posi ons. Display the binary representa on of the shi ed value.
5. Bitwise Right Shi : Write a C program that takes an integer and shi s its bits to the right by a
specified number of posi ons. Display the binary representa on of the shi ed value.
6. Toggle Nth Bit: Create a C program that toggles the nth bit of an integer (sets it to 0 if it's 1 and
vice versa). Display the resul ng integer in binary.
7. Check Even or Odd: Write a C program that checks whether a given integer is even or odd using
bitwise operators.
8. Count Set Bits: Develop a C program that counts the number of set (1) bits in a given integer using
bitwise opera ons.
9. Swap Two Numbers: Create a C program to swap the values of two integers using bitwise operators
without using a temporary variable.
10. Is Power of Two: Write a C program to check if a given posi ve integer is a power of two using
bitwise operators. Return 1 if it is and 0 if it's not.
11. Calcula ng a Number's Half: Write a C program that takes an integer as input and calculates half
of the number while ignoring the frac onal part. Implement this calcula on using bitwise
operators. For example, if the input is 7, the program should output 3, as half of 7 is 3.5, and we
ignore the frac onal part.
12. Set nth bit as 1: Write a C program that sets the nth bit (0-based index) of a given integer to 1 and
then prints both the binary and decimal representa ons of the modified number. (For example, if
the input is num = 10 and n = 2, your program should set the 2nd bit of 10 to 1, resul ng in 14,
and then display both the binary and decimal forms: "Binary: 1110, Decimal: 14".)