 # Bitwise operators in C++

In this tutorial, we are going to explore bitwise operators in C++. As the name says, here, we are going to do operations on bits(binary digits). We will see what are some symbols related to bitwise operators in C++, and we will also go through a simple example, to understand the working of these operators.

## Bitwise operators in C++

As you can see from the above table, we have listed some of the bitwise operators used in C++. Now, let’s have a look at a simple program, through which, we will try to demonstrate the working of bitwise operators, and we will try to use them.

#include <iostream>

int main()
{
int a = 10, b = 2;
std::cout << “a & b: “<< (a&b) << std::endl;
std::cout << “a | b: “<< (a|b) << std::endl;
std::cout << “a ^ b: “<< (a^b) << std::endl;
std::cout << “~a: “<< (~a) << std::endl;
std::cout << “a << 2: “<< (a <<2) << std::endl;
std::cout << “a >> 2: “<< (a >> 2) << std::endl;
return 0;
}

As you can see in the above program, we have tried to use the bitwise operators. Remember that the operations here are done on bits. Here is the output of the above program.

a & b: 2
a | b: 10
a ^ b: 8
~a: -11
a << 2: 40
a >> b: 2

As you can see from the output, we could perform the operations on the bits, using the bitwise operators. You can use the bitwise operators as and when required in your C++ programs. Please keep a note of this, with the bitwise operators, we are doing operations on bits. At times, you might want to use the bitwise operators in your programs.

If you find this tutorial to be interesting, you can explore our other tutorials related to C++ programming language to learn more about C++ programming language. You can also explore our other courses, related to Python, Machine learning, and Data Science, through which, you can upskill yourself.

### Q: What are bitwise operators?

Ans: Using the bitwise operators, we can perform operations on the bits. There are different bitwise operator symbols available for different bitwise operations.

### Q: What are some bitwise operator symbols?

Ans: Here are some bitwise operator symbols in C++ (&, |, ^, ~, >>, <<)