Bitwise Operator in C17 Mar 2025 | 5 min read The bitwise operators are the operators used to perform the operations on the data at the bit-level. When we perform the bitwise operations, then it is also known as bit-level programming. It consists of two digits, either 0 or 1. It is mainly used in numerical computations to make the calculations faster. We have different types of bitwise operators in the C programming language. The following is the list of the bitwise operators:
Let's look at the truth table of the bitwise operators.
Bitwise AND operatorBitwise AND operator is denoted by the single ampersand sign (&). Two integer operands are written on both sides of the (&) operator. If the corresponding bits of both the operands are 1, then the output of the bitwise AND operation is 1; otherwise, the output would be 0. For example, As we can observe from the above result that bits of both the variables are compared one by one. If the bit of both the variables is 1 then the output would be 1, otherwise 0. Let's understand the bitwise AND operator through the program. In the above code, we have created two variables, i.e., 'a' and 'b'. The values of 'a' and 'b' are 6 and 14 respectively. The binary value of 'a' and 'b' are 0110 and 1110, respectively. When we apply the AND operator between these two variables, a AND b = 0110 && 1110 = 0110 Output ![]() Bitwise OR operatorThe bitwise OR operator is represented by a single vertical sign (|). Two integer operands are written on both sides of the (|) symbol. If the bit value of any of the operand is 1, then the output would be 1, otherwise 0. For example, As we can observe from the above result that the bits of both the operands are compared one by one; if the value of either bit is 1, then the output would be 1 otherwise 0. Let's understand the bitwise OR operator through a program. Output ![]() Bitwise exclusive OR operatorBitwise exclusive OR operator is denoted by (^) symbol. Two operands are written on both sides of the exclusive OR operator. If the corresponding bit of any of the operand is 1 then the output would be 1, otherwise 0. For example, As we can observe from the above result that the bits of both the operands are compared one by one; if the corresponding bit value of any of the operand is 1, then the output would be 1 otherwise 0. Let's understand the bitwise exclusive OR operator through a program. Output ![]() Bitwise complement operatorThe bitwise complement operator is also known as one's complement operator. It is represented by the symbol tilde (~). It takes only one operand or variable and performs complement operation on an operand. When we apply the complement operation on any bits, then 0 becomes 1 and 1 becomes 0. For example, As we can observe from the above result that if the bit is 1, then it gets changed to 0 else 1. Let's understand the complement operator through a program. Output ![]() Bitwise shift operatorsTwo types of bitwise shift operators exist in C programming. The bitwise shift operators will shift the bits either on the left-side or right-side. Therefore, we can say that the bitwise shift operator is divided into two categories:
Left-shift operator It is an operator that shifts the number of bits to the left-side. Syntax of the left-shift operator is given below: Where, Operand is an integer expression on which we apply the left-shift operation. n is the number of bits to be shifted. In the case of Left-shift operator, 'n' bits will be shifted on the left-side. The 'n' bits on the left side will be popped out, and 'n' bits on the right-side are filled with 0. For example, Let's understand through a program. Output ![]() Right-shift operator It is an operator that shifts the number of bits to the right side. Syntax of the right-shift operator is given below: Where, Operand is an integer expression on which we apply the right-shift operation. N is the number of bits to be shifted. In the case of the right-shift operator, 'n' bits will be shifted on the right-side. The 'n' bits on the right-side will be popped out, and 'n' bits on the left-side are filled with 0. For example, Let's understand through a program. Output ![]() Next Topic2s complement in C |
Keywords in C Keywords in C are reserved words that have predefined meanings and are part of the C language syntax. These keywords cannot be used as variable names, function names, or any other identifiers within the program except for their intended purpose. They are used...
10 min read
In C programming language, operators are special symbols that are mainly used to perform operations on variables and values on operands. Operators are essential concepts of any programming language. There can be several operations, including arithmetic, value assignment, bitwise, and logical, relational computations. Operator allows...
17 min read
Compile-time and Runtime are the two programming terms used in the software development. Compile-time is the time at which the source code is converted into an executable code while the run time is the time at which the executable code is started running. Both the compile-time...
5 min read
Compilation process in c What is a compilation? The compilation is a process of converting the source code into object code. It is done with the help of the compiler. The compiler checks the source code for the syntactical or structural errors, and if the source code is...
3 min read
A variable is the name of the memory location. It is used to store information. Its value can be altered and reused several times. It is a way to represent memory location through symbols so that it can be easily identified. Variables are key building elements...
6 min read
Structure of C Program The structure of a C program means the specific structure to start the programming in the C language. Without a proper structure, it becomes difficult to analyze the problem and the solution. It also gives us a reference to write more complex programs. Let's...
9 min read
Errors are the problems or the faults that occur in the program, which makes the behavior of the program abnormal, and experienced developers can also make these faults. Programming errors are also known as the bugs or faults, and the process of removing these bugs is...
4 min read
There are many compilers available for c and c++. You need to download any one. Here, we are going to use Turbo C++. It will work for both C and C++. To install the Turbo C software, you need to follow following steps. Download Turbo C++ Create turboc...
1 min read
The conditional operator is also known as a ternary operator. The conditional statements are the decision-making statements which depends upon the output of the expression. It is represented by two symbols, i.e., '?' and ':'. As conditional operator works on three operands, so it is also known...
3 min read
Language C is the widely used language. It provides many features that are given below. Simple Machine Independent or Portable Mid-level programming language structured programming language Rich Library Memory Management Fast Speed Pointers Recursion Extensible 1) Simple C is a simple language in the sense that it provides a structured approach (to break the problem into parts), the...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India