Bitwise Operator in C - javatpoint
文章推薦指數: 80 %
Bitwise AND operator is denoted by the single ampersand sign (&). Two integer operands are written on both sides of the (&) operator. If the corresponding bits ...
⇧SCROLLTOTOP
Home
C
C++
C#
Java
SQL
HTML
CSS
JavaScript
XML
Ajax
Android
Cloud
DesignPattern
Quiz
Projects
InterviewQ
Comment
Forum
CTutorial
WhatisCLanguage
HistoryofC
FeaturesofC
HowtoinstallC
FirstCProgram
CompilationProcessinC
printfscanf
VariablesinC
DataTypesinc
Keywordsinc
CIdentifiers
COperators
CComments
CFormatSpecifier
CEscapeSequence
ASCIIvalueinC
ConstantsinC
LiteralsinC
TokensinC
CBoolean
StaticinC
ProgrammingErrorsinC
CompiletimevsRuntime
ConditionalOperatorinC
BitwiseOperatorinC
2scomplementinC
CFundamentalTest
CControlStatements
Cif-else
Cswitch
if-elsevsswitch
CLoops
Cdo-whileloop
Cwhileloop
Cforloop
NestedLoopsinC
InfiniteLoopinC
Cbreak
Ccontinue
Cgoto
TypeCasting
CControlStatementTest
CFunctions
Whatisfunction
Call:Value&Reference
Recursioninc
StorageClasses
CFunctionsTest
CArray
1-DArray
2-DArray
ReturnanArrayinC
ArraytoFunction
CArrayTest
CPointers
CPointers
CPointertoPointer
CPointerArithmetic
DanglingPointersinC
sizeof()operatorinC
constPointerinC
voidpointerinC
CDereferencePointer
NullPointerinC
CFunctionPointer
FunctionpointerasargumentinC
CPointersTest
CDynamicMemory
Dynamicmemory
CStrings
StringinC
Cgets()&puts()
CStringFunctions
Cstrlen()
Cstrcpy()
Cstrcat()
Cstrcmp()
Cstrrev()
Cstrlwr()
Cstrupr()
Cstrstr()
CStringTest
CMath
CMathFunctions
CStructureUnion
CStructure
typedefinC
CArrayofStructures
CNestedStructure
StructurePaddinginC
CUnion
CStructureTest
CFileHandling
CFileHandling
Cfprintf()fscanf()
Cfputc()fgetc()
Cfputs()fgets()
Cfseek()
Crewind()
Cftell()
CPreprocessor
CPreprocessor
CMacros
C#include
C#define
C#undef
C#ifdef
C#ifndef
C#if
C#else
C#error
C#pragma
CPreprocessorTest
CCommandLine
CommandLineArguments
CMisc
CExpressions
DataSegments
FlowofCProgram
ClassificationofProgrammingLanguages
EnuminC
Whatisgetch()inC
WhatisthefunctioncallinC
typedefvsdefineinC
CProgrammingTest
CProgrammingTest
CPrograms
Top10+CPrograms
FibonacciSeries
PrimeNumber
PalindromeNumber
Cprogramtocomparethetwostrings
StringsConcatenationinC
Factorial
ArmstrongNumber
Sumofdigits
CountthenumberofdigitsinC
ReverseNumber
SwapNumber
Print"Hello"without;
AssemblycodeinC
Cprogramwithoutmain
MatrixMultiplication
DecimaltoBinary
NumberinCharacters
AlphabetTriangle
NumberTriangle
FibonacciTriangle
HexadecimaltoBinary
HexadecimaltoDecimal
OctaltoHexadecimalinC
StrongnumberinC
StarPrograminC
itoaFunctioninC
ExtraLongFactorialsinC
LeapyearprograminC
PerfectNumberPrograminC
VariablesvsConstants
RoundRobinPrograminCwithOutput
CProgramtofindtherootsofquadraticequation
TypeCastingvsTypeConversion
HowtorunaCprograminVisualStudioCode
ModulusOperatorinC/C++
SumoffirstNnaturalnumbersinC
BigONotationinC
LCMoftwonumbersinC
whileloopvsdo-whileloopinC
MemoryLayoutinC
BalancedParenthesisinC
BinarytoDecimalNumberinC
GCDoftwonumbersinC
Getchar()functioninC
flowchartinC
SimpsonMethod
PyramidPatternsinC
RandomFunctioninC
Floyd'sTriangleinC
CHeaderFiles
abs()functioninC
Atoi()functioninC
StructurePointerinC
sprintf()inC
RangeofIntinC
CProgramtoconvert24Hourtimeto12Hourtime
WhatisdoubleinC
WhatisthemaininC
CalculatorPrograminC
CallocinC
user-definedvslibraryfunctioninC
MemsetC
ASCIITableinC
StaticfunctioninC
ReverseaStringinC
TwinPrimeNumbersinC
strchr()functioninC
StructureofaCprogram
PowerFunctioninC
MallocinC
TablePrograminC
TypesofRecursioninC
ConvertUppercasetoLowercaseinC
UnaryOperatorinC
ArithmeticOperatorinC
CeilFunctioninC
RelationalOperatorinC
AssignmentOperatorinC
Pre-incrementandPost-incrementOperatorinC
PointervsarrayinC
RestrictkeywordinC
Theexit()functioninC
ConstQualifierinC
SequencePointsinC
AnagraminC
IncrementandDecrementOperatorsinC
LogicalANDOperatorinC
ShiftOperatorsinC
Near,Far,andHugepointersinClanguage
MagicNumberinC
RemoveDuplicateElementsfromanArrayinC
GenericLinkedlistinC
isalnum()functioninC
isalpha()functioninC
BisectionMethodinC
snprintf()functioninC
RemoveanelementfromanarrayinC
SquareRootinC
isprint()functioninC
isdigit()functioninC
isgraph()functioninC
LogicalNOT(!)OperatorinC
Self-referentialstructure
BreakVs.ContinueinC
Forvs.WhileloopinC
MCQ
ClanguageMCQ
ClanguageMCQPart2
Math
PrimeNumbersList
CompositeNumbersList
SquareNumbersList
BinaryNumbersList
FibonacciNumbersList
OuncesinaCup
OuncesinaPound
OuncesinaGallon
OuncesinaLiter
OuncesinaPint
OuncesinaQuart
OuncesinaTablespoon
CInterview
CInterviewQuestions
next→
←prev
BitwiseOperatorinC
Thebitwiseoperatorsaretheoperatorsusedtoperformtheoperationsonthedataatthebit-level.Whenweperformthebitwiseoperations,thenitisalsoknownasbit-levelprogramming.Itconsistsoftwodigits,either0or1.Itismainlyusedinnumericalcomputationstomakethecalculationsfaster.
WehavedifferenttypesofbitwiseoperatorsintheCprogramminglanguage.Thefollowingisthelistofthebitwiseoperators:
Operator
Meaningofoperator
&
BitwiseANDoperator
|
BitwiseORoperator
^
BitwiseexclusiveORoperator
~
One'scomplementoperator(unaryoperator)
<<
Leftshiftoperator
>>
Rightshiftoperator
Let'slookatthetruthtableofthebitwiseoperators.
X
Y
X&Y
X|Y
X^Y
0
0
0
0
0
0
1
0
1
1
1
0
0
1
1
1
1
1
1
1
BitwiseANDoperator
BitwiseANDoperatorisdenotedbythesingleampersandsign(&).Twointegeroperandsarewrittenonbothsidesofthe(&)operator.Ifthecorrespondingbitsofboththeoperandsare1,thentheoutputofthebitwiseANDoperationis1;otherwise,theoutputwouldbe0.
Forexample,
Wehavetwovariablesaandb.
a=6;
b=4;
Thebinaryrepresentationoftheabovetwovariablesaregivenbelow:
a=0110
b=0100
WhenweapplythebitwiseANDoperationintheabovetwovariables,i.e.,a&b,theoutputwouldbe:
Result=0100
Aswecanobservefromtheaboveresultthatbitsofboththevariablesarecomparedonebyone.Ifthebitofboththevariablesis1thentheoutputwouldbe1,otherwise0.
Let'sunderstandthebitwiseANDoperatorthroughtheprogram.
#include
延伸文章資訊
- 1Bitwise Operators in C Programming - Programiz
In this tutorial you will learn about all 6 bitwise operators in C programming with examples. In ...
- 2Bitwise Operators in C - Tutorialspoint
Bitwise Operators in C ; <<, Binary Left Shift Operator. The left operands value is moved left by...
- 3Bitwise Operators in C [With Coding Example] | upGrad blog
- 4Bitwise Operators in C: AND, OR, XOR, Shift & Complement
Bitwise operators are special operator set provided by 'C.' · They are used in bit level programm...
- 5Bitwise Operators in C: AND, OR, XOR, Shift & Complement