0% found this document useful (0 votes)
11 views

C Bitwose operator

The document provides an overview of operators in C, including logical, bitwise, and assignment operators. It explains the functionality of various bitwise operators with examples and their outputs. Additionally, it describes assignment operators and their role in assigning values to variables.

Uploaded by

neeraj.bhopal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

C Bitwose operator

The document provides an overview of operators in C, including logical, bitwise, and assignment operators. It explains the functionality of various bitwise operators with examples and their outputs. Additionally, it describes assignment operators and their role in assigning values to variables.

Uploaded by

neeraj.bhopal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1/26/25, 6:19 PM Operators in C - GeeksforGeeks

return 0;
15 }

Output

a && b : 1
a || b : 1
!a: 0

4. Bitwise Operators in C
The Bitwise operators are used to perform bit-level operations on the
operands. The operators are first converted to bit-level and then the
calculation is performed on the operands. Mathematical operations such
as addition, subtraction, multiplication, etc. can be performed at the bit
level for faster processing.

There are 6 bitwise operators in C:

S. No. Symbol Operator Description Syntax

1 Performs bit-
by-bit AND
& Bitwise AND operation and a&b
returns the
result.

2 Performs bit-
by-bit OR
| Bitwise OR operation and a|b
returns the
result.

3 Performs bit-
by-bit XOR
^ Bitwise XOR operation and a^b
returns the
result.

https://www.geeksforgeeks.org/operators-in-c/ 8/27
1/26/25, 6:19 PM Operators in C - GeeksforGeeks

S. No. Symbol Operator Description Syntax

4 Flips all the

~ Bitwise First set and unset


~a
Complement bits on the
number.

5 Shifts the
number in
binary form by
Bitwise
<< one place in a << b
Leftshift
the operation
and returns
the result.

6 Shifts the
number in
binary form by
>> Bitwise
one place in a >> b
Rightshilft
the operation
and returns
the result.

Example of Bitwise Operators

1 // C program to illustrate the bitwise operators


2 #include <stdio.h>
3
4 int main()
5 {
6
7 int a = 25, b = 5;
8
9 // using operators and printing results
10 printf("a & b: %d\n", a & b);
11 printf("a | b: %d\n", a | b);
12 printf("a ^ b: %d\n", a ^ b);
13 printf("~a: %d\n", ~a);
https://www.geeksforgeeks.org/operators-in-c/ 9/27
1/26/25, 6:19 PM Operators in C - GeeksforGeeks

printf("a >> b: %d\n", a >> b);


15 printf("a << b: %d\n", a << b);
16
17 return 0;
18 }

Output

a & b: 1
a | b: 29
a ^ b: 28
~a: -26
a >> b: 0
a << b: 800

5. Assignment Operators in C
Assignment operators are used to assign value to a variable. The left
side operand of the assignment operator is a variable and the right side
operand of the assignment operator is a value. The value on the right
side must be of the same data type as the variable on the left side
otherwise the compiler will raise an error.

The assignment operators can be combined with some other operators


in C to provide multiple operations using single operator. These
operators are called compound operators.

In C, there are 11 assignment operators :

S. No. Symbol Operator Description Syntax

1 Assign the
value of the
= Simple a=b
right operand
Assignment
to the left
operand.

https://www.geeksforgeeks.org/operators-in-c/ 10/27

You might also like