SlideShare a Scribd company logo
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 operators
alldesign
 
Comp Arithmetic Basic.ppt
Comp Arithmetic Basic.pptComp Arithmetic Basic.ppt
Comp Arithmetic Basic.ppt
skatiarrahaman
 
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
manjunath V Gudur
 
Mba admission in india
Mba admission in indiaMba admission in india
Mba admission in india
Edhole.com
 
Multiplication algorithm
Multiplication algorithmMultiplication algorithm
Multiplication algorithm
Gaurav Subham
 
COA(Unit_3.pptx)
COA(Unit_3.pptx)COA(Unit_3.pptx)
COA(Unit_3.pptx)
Thapar Institute
 
Alu1
Alu1Alu1
module 1_class_numbers.pptx
module 1_class_numbers.pptxmodule 1_class_numbers.pptx
module 1_class_numbers.pptx
ssuser2efca7
 
Chapter 2_Number system (EEEg4302).pdf
Chapter 2_Number system (EEEg4302).pdfChapter 2_Number system (EEEg4302).pdf
Chapter 2_Number system (EEEg4302).pdf
TamiratDejene1
 
CA UNIT II.pptx
CA UNIT II.pptxCA UNIT II.pptx
CA UNIT II.pptx
ssuser9dbd7e
 
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 system
MahiboobAliMulla
 
Computer arithmetic
Computer arithmeticComputer arithmetic
Computer arithmetic
Usiju Gadzama
 
Representation of Integers
Representation of IntegersRepresentation of Integers
Representation of Integers
Susantha Herath
 
Chapter 6
Chapter 6Chapter 6

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

Data Management Activities, Extraction, Transformation and Loading (ETL)
Data Management Activities, Extraction, Transformation and Loading (ETL)Data Management Activities, Extraction, Transformation and Loading (ETL)
Data Management Activities, Extraction, Transformation and Loading (ETL)
Megha Sharma
 
Descriptive Statistics: Mean, Median Mode and Standard Deviation.
Descriptive Statistics: Mean, Median Mode and Standard Deviation.Descriptive Statistics: Mean, Median Mode and Standard Deviation.
Descriptive Statistics: Mean, Median Mode and Standard Deviation.
Megha Sharma
 
Model Evaluation Matrix: Confusion Matrix, F1 Score, ROC curve AUC
Model Evaluation Matrix: Confusion Matrix, F1 Score, ROC curve AUCModel Evaluation Matrix: Confusion Matrix, F1 Score, ROC curve AUC
Model Evaluation Matrix: Confusion Matrix, F1 Score, ROC curve AUC
Megha Sharma
 
Model Evaluation Matrix: Accuracy, precision and recall
Model Evaluation Matrix: Accuracy, precision and recallModel Evaluation Matrix: Accuracy, precision and recall
Model Evaluation Matrix: Accuracy, precision and recall
Megha Sharma
 
Visualization Techniques- Box plot, Line Chart, Scatter plot, Bar chart.
Visualization Techniques- Box plot, Line Chart, Scatter plot, Bar chart.Visualization Techniques- Box plot, Line Chart, Scatter plot, Bar chart.
Visualization Techniques- Box plot, Line Chart, Scatter plot, Bar chart.
Megha Sharma
 
Visualization Techniques ,Exploratory Data Analysis(EDA), Histogram
Visualization Techniques ,Exploratory Data Analysis(EDA), HistogramVisualization Techniques ,Exploratory Data Analysis(EDA), Histogram
Visualization Techniques ,Exploratory Data Analysis(EDA), Histogram
Megha Sharma
 
Data Preprocessing- Data transformation, Scaling, Normalization, Standardiza...
Data Preprocessing- Data transformation,  Scaling, Normalization, Standardiza...Data Preprocessing- Data transformation,  Scaling, Normalization, Standardiza...
Data Preprocessing- Data transformation, Scaling, Normalization, Standardiza...
Megha Sharma
 
Data Science- Data Preprocessing, Data Cleaning.
Data Science- Data Preprocessing, Data Cleaning.Data Science- Data Preprocessing, Data Cleaning.
Data Science- Data Preprocessing, Data Cleaning.
Megha Sharma
 
Data Preprocessing- Feature Selection and Merging.
Data Preprocessing- Feature Selection and Merging.Data Preprocessing- Feature Selection and Merging.
Data Preprocessing- Feature Selection and Merging.
Megha Sharma
 
Different types of data. Qualitative, Quantitative, Ordinal, Nominal, Discret...
Different types of data. Qualitative, Quantitative, Ordinal, Nominal, Discret...Different types of data. Qualitative, Quantitative, Ordinal, Nominal, Discret...
Different types of data. Qualitative, Quantitative, Ordinal, Nominal, Discret...
Megha Sharma
 
Data Science comparison with AI, ML, BI, and data warehousing, data mining.
Data Science comparison with AI, ML, BI, and data warehousing, data mining.Data Science comparison with AI, ML, BI, and data warehousing, data mining.
Data Science comparison with AI, ML, BI, and data warehousing, data mining.
Megha Sharma
 
Data Science Introduction, Application of Data Science.
Data Science Introduction, Application of Data Science.Data Science Introduction, Application of Data Science.
Data Science Introduction, Application of Data Science.
Megha Sharma
 
Ensemble learning
Ensemble learningEnsemble learning
Ensemble learning
Megha Sharma
 
Association Rule mining
Association Rule miningAssociation Rule mining
Association Rule mining
Megha Sharma
 
Bellman's equation Reinforcement learning - II
Bellman's equation Reinforcement learning - IIBellman's equation Reinforcement learning - II
Bellman's equation Reinforcement learning - II
Megha Sharma
 
Reinforcement learning in Machine learning
 Reinforcement learning in Machine learning Reinforcement learning in Machine learning
Reinforcement learning in Machine learning
Megha Sharma
 
E-M Algorithm
E-M AlgorithmE-M Algorithm
E-M Algorithm
Megha 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 C
Megha Sharma
 

More from Megha Sharma (20)

Data Management Activities, Extraction, Transformation and Loading (ETL)
Data Management Activities, Extraction, Transformation and Loading (ETL)Data Management Activities, Extraction, Transformation and Loading (ETL)
Data Management Activities, Extraction, Transformation and Loading (ETL)
 
Descriptive Statistics: Mean, Median Mode and Standard Deviation.
Descriptive Statistics: Mean, Median Mode and Standard Deviation.Descriptive Statistics: Mean, Median Mode and Standard Deviation.
Descriptive Statistics: Mean, Median Mode and Standard Deviation.
 
Model Evaluation Matrix: Confusion Matrix, F1 Score, ROC curve AUC
Model Evaluation Matrix: Confusion Matrix, F1 Score, ROC curve AUCModel Evaluation Matrix: Confusion Matrix, F1 Score, ROC curve AUC
Model Evaluation Matrix: Confusion Matrix, F1 Score, ROC curve AUC
 
Model Evaluation Matrix: Accuracy, precision and recall
Model Evaluation Matrix: Accuracy, precision and recallModel Evaluation Matrix: Accuracy, precision and recall
Model Evaluation Matrix: Accuracy, precision and recall
 
Visualization Techniques- Box plot, Line Chart, Scatter plot, Bar chart.
Visualization Techniques- Box plot, Line Chart, Scatter plot, Bar chart.Visualization Techniques- Box plot, Line Chart, Scatter plot, Bar chart.
Visualization Techniques- Box plot, Line Chart, Scatter plot, Bar chart.
 
Visualization Techniques ,Exploratory Data Analysis(EDA), Histogram
Visualization Techniques ,Exploratory Data Analysis(EDA), HistogramVisualization Techniques ,Exploratory Data Analysis(EDA), Histogram
Visualization Techniques ,Exploratory Data Analysis(EDA), Histogram
 
Data Preprocessing- Data transformation, Scaling, Normalization, Standardiza...
Data Preprocessing- Data transformation,  Scaling, Normalization, Standardiza...Data Preprocessing- Data transformation,  Scaling, Normalization, Standardiza...
Data Preprocessing- Data transformation, Scaling, Normalization, Standardiza...
 
Data Science- Data Preprocessing, Data Cleaning.
Data Science- Data Preprocessing, Data Cleaning.Data Science- Data Preprocessing, Data Cleaning.
Data Science- Data Preprocessing, Data Cleaning.
 
Data Preprocessing- Feature Selection and Merging.
Data Preprocessing- Feature Selection and Merging.Data Preprocessing- Feature Selection and Merging.
Data Preprocessing- Feature Selection and Merging.
 
Different types of data. Qualitative, Quantitative, Ordinal, Nominal, Discret...
Different types of data. Qualitative, Quantitative, Ordinal, Nominal, Discret...Different types of data. Qualitative, Quantitative, Ordinal, Nominal, Discret...
Different types of data. Qualitative, Quantitative, Ordinal, Nominal, Discret...
 
Data Science comparison with AI, ML, BI, and data warehousing, data mining.
Data Science comparison with AI, ML, BI, and data warehousing, data mining.Data Science comparison with AI, ML, BI, and data warehousing, data mining.
Data Science comparison with AI, ML, BI, and data warehousing, data mining.
 
Data Science Introduction, Application of Data Science.
Data Science Introduction, Application of Data Science.Data Science Introduction, Application of Data Science.
Data Science Introduction, Application of Data Science.
 
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
 

Recently uploaded

Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 

Recently uploaded (20)

Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 

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