# Bit Manipulation (level- 1)

1. All bitwise operator working
    

```cpp
#include <bits/stdc++.h>
using namespace std;
void bitwiseAnd(int a, int b)
{
  cout << (a & b);
}
void bitwiseOr(int a, int b)
{
  cout << (a | b);
}
void bitwiseXor(int a, int b)
{
  cout << (a ^ b);
}
void leftShift(int a, int b)
{
  cout << (a << b);
}
void rightShift(int a, int b)
{
  cout << (a >> b);
}
void bitwiseNot(int a)
{
  cout << (~a);
}
```

2. Check if kth bit set or not
    

```cpp
void isKthBitSet(int n, int k)
{
	if (n & (1 << (k - 1)))
		cout << "SET";
	else
		cout << "NOT SET";
}
```

3. Count set bits
    

```cpp
int countSetBits(int n)
	{
	    int count = 0;
		while (n) {
			n =n & (n - 1);
			count++;
		}
		return count;
	}
```

4. Power of two or not
    

```cpp
bool isPowerofTwo(long long n)
{
	return (n&((n&(n-1))==0);
}
```

5. One odd occuring
    

```cpp
int getOddOccurrence(int ar[], int ar_size)
{
	int res = 0;
	for (int i = 0; i < ar_size; i++)	
		res = res ^ ar[i];
	
	return res;
}
```
