SlideShare a Scribd company logo
1 of 12
Download to read offline
Operators in C
Bitwise Operators
Bitwise Operators
In the arithmetic-logic unit (which is within the CPU), mathematical operations
like: addition, subtraction, multiplication and division are done in bit-level. To
perform bit-level operations in C programming, bitwise operators are used.
The truth tables for & (Bitwise AND), |(Bitwise OR), and ^(Bitwise XOR)
is as follows −
M N M & N M | N M ^ N
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
Bitwise AND
The output of bitwise AND is 1 if the corresponding bits of two
operands is 1. If either bit of an operand is 0, the result of
corresponding bit is evaluated to 0. Bitwise AND operator is
denoted by &.
Let us suppose the bitwise AND operation of two integers 5 and 9.
5 0101
9 1001
5&9 0001 =1 (In decimal)
0 1 0 1
1 0 0 1
0 0 0 1
Bitwise OR
The output of bitwise OR is 1 if at least one corresponding bit of
two operands is 1. In C Programming, bitwise OR operator is
denoted by | .
Let us suppose the bitwise OR operation of two integers 5 and 9.
5 0101
9 1001
5|9 1101 =13 (In decimal)
0 1 0 1
1 0 0 1
1 1 1
0
Bitwise XOR
The result of bitwise XOR operator is 1 if the corresponding bits of
two operands are opposite. It is denoted by ^.
Let us suppose the bitwise XOR operation of two integers 5 and 9.
5 0101
9 1001
5^9 1100 =12 (In decimal)
0 1 0 1
1 0 0 1
1 1 0 0
Bitwise Complement
Bitwise complement operator is a unary operator (works on only one
operand). It changes 1 to 0 and 0 to 1. It is denoted by ~ .
5 0101
~5 1010 =10 (In decimal)
0 1 0 1
1 0 1 0
For any integer n bitwise complement of n will be -(n+1) .
The bitwise complement of 5 is 10 (in decimal). The 2's complement
of 10 is -6 . Hence, the output is -6
Left Shift Operator
Left shift operator shifts all bits towards left by certain
number of specified bits. It is denoted by <<.
Example 5 << 1
5 = 0101 (In Binary)
5 << 1 = 1010 (Left shift by 1 bits)
(In decimal 10)
0 1 0 1
1 0 1 0
Left shift operator is used to multiply the number by 2n
where n is number of bits
Right Shift Operator
Right shift operator shifts all bits towards right by certain
number of specified bits. It is denoted by >>.
Example 5 = 0101 (In Binary)
5 >> 1 = 0010 (Right shift by 1 bits)
(In decimal 2)
0 1 0 1
1 0
0
0
Right shift operator is used to divide the number by 2n
where n is number of bits
SUMMARY
Example A=5 B=9
Operators Meaning Example
& Perform bitwise AND operation. (A&B) = 1
i.e. 0001
| Perform bitwise OR operation. (A|B) = 13
i.e. 1101
^ Perform bitwise XOR operation. (A^B) = 12
i.e. 1100
~ Perform bitwise NOT operation. ~A = 10
i.e. 1010
<< Binary Left shift operator shifts all bits towards left by
certain number of specified bits. It is denoted by <<.
A<<1 = 1010
i.e. 10
>> Binary Right shift operator shifts all bits towards right
by certain number of specified bits.
A>>1 = 0010
i.e. 2
THANK YOU

More Related Content

Similar to Bitwise operators

Bit shift operators
Bit shift operatorsBit shift operators
Bit shift operatorsalldesign
 
Comp Arithmetic Basic.ppt
Comp Arithmetic Basic.pptComp Arithmetic Basic.ppt
Comp Arithmetic Basic.pptskatiarrahaman
 
Module 4_Digital Electronics till complements.pdf
Module 4_Digital Electronics till complements.pdfModule 4_Digital Electronics till complements.pdf
Module 4_Digital Electronics till complements.pdfmanjunath V Gudur
 
Mba admission in india
Mba admission in indiaMba admission in india
Mba admission in indiaEdhole.com
 
Multiplication algorithm
Multiplication algorithmMultiplication algorithm
Multiplication algorithmGaurav Subham
 
module 1_class_numbers.pptx
module 1_class_numbers.pptxmodule 1_class_numbers.pptx
module 1_class_numbers.pptxssuser2efca7
 
Chapter 2_Number system (EEEg4302).pdf
Chapter 2_Number system (EEEg4302).pdfChapter 2_Number system (EEEg4302).pdf
Chapter 2_Number system (EEEg4302).pdfTamiratDejene1
 
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...IRJET Journal
 
B sc3 unit 2 number system
B sc3  unit 2 number systemB sc3  unit 2 number system
B sc3 unit 2 number systemMahiboobAliMulla
 
Representation of Integers
Representation of IntegersRepresentation of Integers
Representation of IntegersSusantha Herath
 

Similar to Bitwise operators (20)

Bit shift operators
Bit shift operatorsBit shift operators
Bit shift operators
 
Comp Arithmetic Basic.ppt
Comp Arithmetic Basic.pptComp Arithmetic Basic.ppt
Comp Arithmetic Basic.ppt
 
Module 4_Digital Electronics till complements.pdf
Module 4_Digital Electronics till complements.pdfModule 4_Digital Electronics till complements.pdf
Module 4_Digital Electronics till complements.pdf
 
2's complement
2's complement2's complement
2's complement
 
Mba admission in india
Mba admission in indiaMba admission in india
Mba admission in india
 
Multiplication algorithm
Multiplication algorithmMultiplication algorithm
Multiplication algorithm
 
COA(Unit_3.pptx)
COA(Unit_3.pptx)COA(Unit_3.pptx)
COA(Unit_3.pptx)
 
Alu1
Alu1Alu1
Alu1
 
module 1_class_numbers.pptx
module 1_class_numbers.pptxmodule 1_class_numbers.pptx
module 1_class_numbers.pptx
 
Report on c
Report on cReport on c
Report on c
 
Chapter 2_Number system (EEEg4302).pdf
Chapter 2_Number system (EEEg4302).pdfChapter 2_Number system (EEEg4302).pdf
Chapter 2_Number system (EEEg4302).pdf
 
CA UNIT II.pptx
CA UNIT II.pptxCA UNIT II.pptx
CA UNIT II.pptx
 
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...
 
B sc3 unit 2 number system
B sc3  unit 2 number systemB sc3  unit 2 number system
B sc3 unit 2 number system
 
09 Arithmetic
09  Arithmetic09  Arithmetic
09 Arithmetic
 
Computer arithmetic
Computer arithmeticComputer arithmetic
Computer arithmetic
 
Representation of Integers
Representation of IntegersRepresentation of Integers
Representation of Integers
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
 
Java - Operators
Java - OperatorsJava - Operators
Java - Operators
 
Java 2
Java 2Java 2
Java 2
 

More from Megha Sharma

Association Rule mining
Association Rule miningAssociation Rule mining
Association Rule miningMegha Sharma
 
Bellman's equation Reinforcement learning - II
Bellman's equation Reinforcement learning - IIBellman's equation Reinforcement learning - II
Bellman's equation Reinforcement learning - IIMegha Sharma
 
Reinforcement learning in Machine learning
 Reinforcement learning in Machine learning Reinforcement learning in Machine learning
Reinforcement learning in Machine learningMegha Sharma
 
Entropy and information gain in decision tree.
Entropy and information gain in decision tree.Entropy and information gain in decision tree.
Entropy and information gain in decision tree.Megha Sharma
 
Types of Machine Learning. & Decision Tree.
Types of Machine Learning. & Decision Tree.Types of Machine Learning. & Decision Tree.
Types of Machine Learning. & Decision Tree.Megha Sharma
 
If statements in C
If statements in CIf statements in C
If statements in CMegha Sharma
 
Conditional and special operators
Conditional and special operatorsConditional and special operators
Conditional and special operatorsMegha Sharma
 
Assignment operators
Assignment operatorsAssignment operators
Assignment operatorsMegha Sharma
 
Relational and logical operators
Relational and logical operatorsRelational and logical operators
Relational and logical operatorsMegha Sharma
 
Arithmetic and increment decrement Operator
Arithmetic and increment decrement OperatorArithmetic and increment decrement Operator
Arithmetic and increment decrement OperatorMegha Sharma
 
Structure of C program
Structure of C programStructure of C program
Structure of C programMegha Sharma
 
Algorithm & Flowchart
Algorithm & FlowchartAlgorithm & Flowchart
Algorithm & FlowchartMegha Sharma
 
C Programming introduction
C Programming introductionC Programming introduction
C Programming introductionMegha Sharma
 
Enhanced ER Models
Enhanced ER ModelsEnhanced ER Models
Enhanced ER ModelsMegha Sharma
 
Entity Relationship design issues
Entity Relationship design issuesEntity Relationship design issues
Entity Relationship design issuesMegha Sharma
 
Participation Constraints in ER diagram
Participation Constraints in ER diagramParticipation Constraints in ER diagram
Participation Constraints in ER diagramMegha Sharma
 
Mapping Cardinalities
Mapping CardinalitiesMapping Cardinalities
Mapping CardinalitiesMegha Sharma
 

More from Megha Sharma (20)

Ensemble learning
Ensemble learningEnsemble learning
Ensemble learning
 
Association Rule mining
Association Rule miningAssociation Rule mining
Association Rule mining
 
Bellman's equation Reinforcement learning - II
Bellman's equation Reinforcement learning - IIBellman's equation Reinforcement learning - II
Bellman's equation Reinforcement learning - II
 
Reinforcement learning in Machine learning
 Reinforcement learning in Machine learning Reinforcement learning in Machine learning
Reinforcement learning in Machine learning
 
E-M Algorithm
E-M AlgorithmE-M Algorithm
E-M Algorithm
 
Entropy and information gain in decision tree.
Entropy and information gain in decision tree.Entropy and information gain in decision tree.
Entropy and information gain in decision tree.
 
Types of Machine Learning. & Decision Tree.
Types of Machine Learning. & Decision Tree.Types of Machine Learning. & Decision Tree.
Types of Machine Learning. & Decision Tree.
 
If statements in C
If statements in CIf statements in C
If statements in C
 
Conditional and special operators
Conditional and special operatorsConditional and special operators
Conditional and special operators
 
Assignment operators
Assignment operatorsAssignment operators
Assignment operators
 
Relational and logical operators
Relational and logical operatorsRelational and logical operators
Relational and logical operators
 
Arithmetic and increment decrement Operator
Arithmetic and increment decrement OperatorArithmetic and increment decrement Operator
Arithmetic and increment decrement Operator
 
Structure of C program
Structure of C programStructure of C program
Structure of C program
 
C tokens
C tokensC tokens
C tokens
 
Algorithm & Flowchart
Algorithm & FlowchartAlgorithm & Flowchart
Algorithm & Flowchart
 
C Programming introduction
C Programming introductionC Programming introduction
C Programming introduction
 
Enhanced ER Models
Enhanced ER ModelsEnhanced ER Models
Enhanced ER Models
 
Entity Relationship design issues
Entity Relationship design issuesEntity Relationship design issues
Entity Relationship design issues
 
Participation Constraints in ER diagram
Participation Constraints in ER diagramParticipation Constraints in ER diagram
Participation Constraints in ER diagram
 
Mapping Cardinalities
Mapping CardinalitiesMapping Cardinalities
Mapping Cardinalities
 

Recently uploaded

EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 

Recently uploaded (20)

EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 

Bitwise operators

  • 2. Bitwise Operators In the arithmetic-logic unit (which is within the CPU), mathematical operations like: addition, subtraction, multiplication and division are done in bit-level. To perform bit-level operations in C programming, bitwise operators are used. The truth tables for & (Bitwise AND), |(Bitwise OR), and ^(Bitwise XOR) is as follows − M N M & N M | N M ^ N 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 1 0
  • 3. Bitwise AND The output of bitwise AND is 1 if the corresponding bits of two operands is 1. If either bit of an operand is 0, the result of corresponding bit is evaluated to 0. Bitwise AND operator is denoted by &. Let us suppose the bitwise AND operation of two integers 5 and 9. 5 0101 9 1001 5&9 0001 =1 (In decimal) 0 1 0 1 1 0 0 1 0 0 0 1
  • 4. Bitwise OR The output of bitwise OR is 1 if at least one corresponding bit of two operands is 1. In C Programming, bitwise OR operator is denoted by | . Let us suppose the bitwise OR operation of two integers 5 and 9. 5 0101 9 1001 5|9 1101 =13 (In decimal) 0 1 0 1 1 0 0 1 1 1 1 0
  • 5. Bitwise XOR The result of bitwise XOR operator is 1 if the corresponding bits of two operands are opposite. It is denoted by ^. Let us suppose the bitwise XOR operation of two integers 5 and 9. 5 0101 9 1001 5^9 1100 =12 (In decimal) 0 1 0 1 1 0 0 1 1 1 0 0
  • 6. Bitwise Complement Bitwise complement operator is a unary operator (works on only one operand). It changes 1 to 0 and 0 to 1. It is denoted by ~ . 5 0101 ~5 1010 =10 (In decimal) 0 1 0 1 1 0 1 0
  • 7. For any integer n bitwise complement of n will be -(n+1) . The bitwise complement of 5 is 10 (in decimal). The 2's complement of 10 is -6 . Hence, the output is -6
  • 8. Left Shift Operator Left shift operator shifts all bits towards left by certain number of specified bits. It is denoted by <<. Example 5 << 1 5 = 0101 (In Binary) 5 << 1 = 1010 (Left shift by 1 bits) (In decimal 10) 0 1 0 1 1 0 1 0 Left shift operator is used to multiply the number by 2n where n is number of bits
  • 9. Right Shift Operator Right shift operator shifts all bits towards right by certain number of specified bits. It is denoted by >>. Example 5 = 0101 (In Binary) 5 >> 1 = 0010 (Right shift by 1 bits) (In decimal 2) 0 1 0 1 1 0 0 0 Right shift operator is used to divide the number by 2n where n is number of bits
  • 10.
  • 11. SUMMARY Example A=5 B=9 Operators Meaning Example & Perform bitwise AND operation. (A&B) = 1 i.e. 0001 | Perform bitwise OR operation. (A|B) = 13 i.e. 1101 ^ Perform bitwise XOR operation. (A^B) = 12 i.e. 1100 ~ Perform bitwise NOT operation. ~A = 10 i.e. 1010 << Binary Left shift operator shifts all bits towards left by certain number of specified bits. It is denoted by <<. A<<1 = 1010 i.e. 10 >> Binary Right shift operator shifts all bits towards right by certain number of specified bits. A>>1 = 0010 i.e. 2