C++ Bitwise Operators - Programiz
文章推薦指數: 80 %
In C++, bitwise operators perform operations on integer data at the individual bit-level. These operations include testing, setting, or shifting the actual ...
CourseIndex
ExploreProgramiz
Python
JavaScript
SQL
C
C++
Java
Kotlin
Swift
C#
DSA
PopularTutorials
C++if...elseStatement
C++forLoop
ArraysinC++
StringsinC++
C++Class&Objects
StartLearningC++
PopularExamples
Createasimplecalculator
Checkprimenumber
PrinttheFibonaccisequence
Checkifanumberispalindromeornot
Programtomultiplymatrix
ExploreC++Examples
ReferenceMaterials
iostream
cmath
cstring
ctime
Viewall
LearningPaths
Challenges
LearnPythonInteractively
TryforFree
Courses
BecomeaPythonMaster
BecomeaCMaster
BecomeaJavaMaster
ViewallCourses
Python
JavaScript
SQL
C
C++
Java
Kotlin
Swift
C#
DSA
PopularTutorials
C++if...elseStatement
C++forLoop
ArraysinC++
StringsinC++
C++Class&Objects
StartLearningC++
AllC++Tutorials
ReferenceMaterials
iostream
cmath
cstring
ctime
Viewall
Python
JavaScript
C
C++
Java
Kotlin
PopularExamples
Createasimplecalculator
Checkprimenumber
PrinttheFibonaccisequence
Checkifanumberispalindromeornot
Programtomultiplymatrix
AllC++Examples
C++Introduction
C++VariablesandLiterals
C++DataTypes
C++BasicI/O
C++TypeConversion
C++Operators
C++Comments
C++FlowControl
C++if...else
C++forLoop
C++do...whileLoop
C++break
C++continue
C++switchStatement
C++gotoStatement
C++Functions
C++Functions
C++FunctionTypes
C++FunctionOverloading
C++DefaultArgument
C++StorageClass
C++Recursion
C++ReturnReference
C++Arrays&String
C++Arrays
MultidimensionalArrays
C++FunctionandArray
C++String
C++Structures
C++Structures
StructureandFunction
C++PointerstoStructure
C++Enumeration
C++Object&Class
C++ObjectsandClass
C++Constructors
C++Objects&Function
C++OperatorOverloading
C++Pointers
C++Pointers
C++PointersandArrays
C++PointersandFunctions
C++MemoryManagement
C++Inheritance
C++Inheritance
InheritanceAccessControl
C++FunctionOverriding
InheritanceTypes
C++FriendFunction
C++VirtualFunction
C++Templates
RelatedTopics
C++OperatorPrecedenceandAssociativity
C++Operators
C++RelationalandLogicalOperators
SubtractComplexNumberUsingOperatorOverloading
MakeaSimpleCalculatortoAdd,Subtract,MultiplyorDivideUsingswitch...case
C++OperatorOverloading
C++BitwiseOperators
Inthistutorial,wewilllearnaboutbitwiseoperatorsinC++withthehelpofexamples.
InC++,bitwiseoperatorsperformoperationsonintegerdataattheindividualbit-level.Theseoperationsincludetesting,setting,orshiftingtheactualbits.Forexample,
a&b;
a|b;
Hereisalistof6bitwiseoperatorsincludedinC++.
Operator
Description
&
BitwiseANDOperator
|
BitwiseOROperator
^
BitwiseXOROperator
~
BitwiseComplementOperator
<<
BitwiseShiftLeftOperator
>>
BitwiseShiftRightOperator
TheseoperatorsarenecessarybecausetheArithmetic-LogicUnit(ALU)presentinthecomputer'sCPUcarriesoutarithmeticoperationsatthebit-level.
Note:Bitwiseoperatorscanonlybeusedalongsidecharandintdatatypes.
1.C++BitwiseANDOperator
ThebitwiseAND&operatorreturns1ifandonlyifboththeoperandsare1.Otherwise,itreturns0.
ThefollowingtabledemonstratestheworkingofthebitwiseANDoperator.Letaandbbetwooperandsthatcanonlytakebinaryvaluesi.e.1and0.
a
b
a&b
0
0
0
0
1
0
1
0
0
1
1
1
Note:Thetableaboveisknownasthe"TruthTable"forthebitwiseANDoperator.
Let'stakealookatthebitwiseANDoperationoftwointegers12and25:
12=00001100(InBinary)
25=00011001(InBinary)
//BitwiseANDOperationof12and25
00001100
&00011001
_________
00001000=8(Indecimal)
Example1:BitwiseAND
#include
延伸文章資訊
- 1Bitwise Operators in C/C++ - GeeksforGeeks
- 2C++ Bitwise Operators - Linux Hint
A bitwise operator is applied to manipulate the individual bits for integers and character data t...
- 3位元AND 運算子:& | Microsoft Docs
C++ 標準語言位AND 運算子語法和使用方式。 ... compile with: /EHsc // Demonstrate bitwise AND #include <iostream> u...
- 4Bitwise Operators in C | GATE Notes - Byju's
- 5Bitwise Operators in C and C++ - Cprogramming.com
The bitwise AND operator is a single ampersand: &. A handy mnemonic is that the small version of ...