Bitwise Operators with examples
Bitwise operator programming exercises and solutions in C
Data in the memory (RAM) is organized as a sequence of bytes. Each byte is a group of eight consecutive bits. Bitwise operators are useful when we need to perform actions on bits of the data.
C supports six bitwise operators.
- Bitwise AND operator
&
- Bitwise OR operator
|
- Bitwise XOR operator
^
- Bitwise complement operator
~
- Bitwise left shift operator
<<
- Bitwise right shift operator
>>
This exercises focuses on mastering bitwise operators. After this exercise you will surely gain some confidence using bitwise operators.
List of bitwise operators exercises
Below is a set of programming exercises that can be used by a beginner or an intermediate programmer to master their skills on bitwise operator.
- Write a C program to check Least Significant Bit (LSB) of a number is set or not.
- Write a C program to check Most Significant Bit (MSB) of a number is set or not.
- Write a C program to get nth bit of a number.
- Write a C program to set nth bit of a number.
- Write a C program to clear nth bit of a number.
- Write a C program to toggle nth bit of a number.
- Write a C program to get highest set bit of a number.
- Write a C program to get lowest set bit of a number.
- Write a C program to count trailing zeros in a binary number.
- Write a C program to count leading zeros in a binary number.
- Write a C program to flip bits of a binary number using bitwise operator.
- Write a C program to count total zeros and ones in a binary number.
- Write a C program to rotate bits of a given number.
- Write a C program to convert decimal to binary number system using bitwise operator.
- Write a C program to swap two numbers using bitwise operator.
- Write a C program to check whether a number is even or odd using bitwise operatorsBasic programming exercises and solutions in C.
Recommended posts
- Basic programming exercises and solutions in C.
- If else programming exercises and solutions in C.
- Switch case programming exercises and solutions in C.
- Conditional operator programming exercises and solutions in C.
- Loop programming exercises and solutions in C.
- Array and matrix programming exercises and solutions in C.
- String programming exercises and solutions in C.
- Function and recursion programming exercises and solutions in C.
- Pointer programming exercises and solutions in C.
Comments
Post a Comment