# Bitwise Operators in C Programming: AND, XOR, OR, Complement and Shift Operations - Codzify Tutorials

2 min 31 sec read Basic There are many Bitwise operators in C as defined below:

& (bitwise AND) :- Takes two numbers as operand and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1.

| (bitwise OR) :- Takes two numbers as operand and does OR on every bit of two numbers. The result of OR is 1 any of the two bits is 1.

^ (bitwise XOR) :- Takes two numbers as operand and does XOR on every bit of two numbers. The result of XOR is 1 if the two bits are different.

<< (left shift) :- Takes two numbers, left shifts the bits of first operand, the second operand decides the number of places to shift.

>> (right shift) :- Takes two numbers, right shifts the bits of first operand, the second operand decides the number of places to shift.

~ (bitwise NOT) :- Takes one number and inverts all bits of it.

## Rule :-

& = 1 & 1 is 1 else 0.

| = any of two bit is 1 then 1 else 0.

^ = if both bits are different then 1 else 0.

a>> 1 = shift the bits of a to right by 1 and replace the first bit from left by 0 .

a>> 2 = shift the bits of a to right by 2 and replace the first two bits from left by 0 .

a<< 1 = shift the bits of a to left by 1 and replace the last bit from right by 0 .

a<< 2 = shift the bits of a to left by 2 and replace the last two bits from right by 0 .

~a = replace 0 by 1 and 1 by 0.

## Example :-

```                a= 5    =    00000101
b= 9    =    00001001
—————————————————————
a&b     =    00000001
a|b     =    00001101
a^b     =    00001100
a>>1    =    00000100
a>>1    =    00001010
~a      =    11111010
```

How was the tutorial? Nice. Right?

## What is your Interview Score?

Test your skillset with the curated questions created by experts around the globe.

Book a free test slot. Now !.

It usually takes 30 mins for an online test and this test will be MCQ based. Get detailed analytics based on your test and recommedations with personalised roadmaps.

Book a test slot. Now!

## Have questions about the trial coding class?

Chat with our experts to discuss

Connect on WhatsApp

## Recommended tutorials

#online compiler for c     #python for programming

#dfs and bfs algorithm     #programming with c language

#storageclass in C    #listcomprehension in python