Bitwise Operators in C/C++ - GeeksforGeeks
文章推薦指數: 80 %
The | (bitwise OR) in C or C++ takes two numbers as operands and does OR on every bit of two numbers. The result of OR is 1 if any of the two ...
Skiptocontent
CoursesForWorkingProfessionalsLIVEDSALiveClassesSystemDesignJavaBackendDevelopmentFullStackLIVEExploreMoreSelf-PacedDSA-SelfPacedSDETheoryAllDevelopmentCoursesExploreMoreForStudentsLIVECompetitiveProgrammingGATELiveCourse2023DataScienceExploreMoreSelf-PacedDSA-SelfPacedCIPJAVA/Python/C++ExploreMoreSchoolCoursesSchoolGuidePythonProgrammingLearnToMakeAppsExploremoreAllCoursesTutorialsAlgorithmsAnalysisofAlgorithmsAsymptoticAnalysisWorst,AverageandBestCasesAsymptoticNotationsLittleoandlittleomeganotationsLowerandUpperBoundTheoryAnalysisofLoopsSolvingRecurrencesAmortizedAnalysisWhatdoes'SpaceComplexity'mean?Pseudo-polynomialAlgorithmsPolynomialTimeApproximationSchemeATimeComplexityQuestionSearchingAlgorithmsSortingAlgorithmsGraphAlgorithmsPatternSearchingGeometricAlgorithmsMathematicalBitwiseAlgorithmsRandomizedAlgorithmsGreedyAlgorithmsDynamicProgrammingDivideandConquerBacktrackingBranchandBoundAllAlgorithmsDataStructuresArraysLinkedListStackQueueBinaryTreeBinarySearchTreeHeapHashingGraphAdvancedDataStructureMatrixStringsAllDataStructuresInterviewCornerCompanyPreparationTopTopicsPracticeCompanyQuestionsInterviewExperiencesExperiencedInterviewsInternshipInterviewsCompetititveProgrammingDesignPatternsSystemDesignTutorialMultipleChoiceQuizzesLanguagesCC++JavaPythonC#JavaScriptjQuerySQLPHPScalaPerlGoLanguageHTMLCSSKotlinML&DataScienceMachineLearningDataScienceCSSubjectsMathematicsOperatingSystemDBMSComputerNetworksComputerOrganizationandArchitectureTheoryofComputationCompilerDesignDigitalLogicSoftwareEngineeringGATEGATEComputerScienceNotesLastMinuteNotesGATECSSolvedPapersGATECSOriginalPapersandOfficialKeysGATE2021DatesGATECS2021SyllabusImportantTopicsforGATECSWebTechnologiesHTMLCSSJavaScriptAngularJSReactJSNodeJSBootstrapjQueryPHPSoftwareDesignsSoftwareDesignPatternsSystemDesignTutorialSchoolLearningSchoolProgrammingMathematicsNumberSystemAlgebraTrigonometryStatisticsProbabilityGeometryMensurationCalculusMathsNotes(Class8-12)Class8NotesClass9NotesClass10NotesClass11NotesClass12NotesNCERTSolutionsClass8MathsSolutionClass9MathsSolutionClass10MathsSolutionClass11MathsSolutionClass12MathsSolutionRDSharmaSolutionsClass8MathsSolutionClass9MathsSolutionClass10MathsSolutionClass11MathsSolutionClass12MathsSolutionPhysicsNotes(Class8-11)Class8NotesClass9NotesClass10NotesClass11NotesChemistryNotesClass8NotesClass9NotesClass10NotesCSExams/PSUsISROISROCSOriginalPapersandOfficialKeysISROCSSolvedPapersISROCSSyllabusforScientist/EngineerExamUGCNETUGCNETCSNotesPaperIIUGCNETCSNotesPaperIIIUGCNETCSSolvedPapersStudentCampusAmbassadorProgramSchoolAmbassadorProgramProjectGeekoftheMonthCampusGeekoftheMonthPlacementCourseCompetititveProgrammingTestimonialsStudentChapterGeekontheTopInternshipCareersJobsApplyforJobsPostaJobHirewithUsKnowaboutJobathonJobathonPracticeAllDSAProblemsProblemoftheDayInterviewSeries:WeeklyContestsBi-WizardCoding:SchoolContestsContestsandEventsPracticeSDESheetCuratedDSAListsTop50ArrayProblemsTop50StringProblemsTop50TreeProblemsTop50GraphProblemsTop50DPProblems
ComewritearticlesforusandgetfeaturedLearnandcodewiththebestindustryexpertsGetaccesstoad-freecontent,doubtassistanceandmore!ComeandfindyourdreamjobwithusGeeksDigestQuizzesGeeksCampusGblogArticlesIDECampusMantriHomeSavedVideosCoursesGBlogPuzzlesWhat'sNew?
ChangeLanguage
ArrayMatrixStringsHashingLinkedListStackQueueBinaryTreeBinarySearchTreeHeapGraphSearchingSortingDivide&ConquerMathematicalGeometricBitwiseGreedyBacktrackingBranchandBoundDynamicProgrammingPatternSearchingRandomized
CompleteInterviewPreparationat20%off|Usecode:PREPAREKAROCheckNow
RelatedArticles
▲RelatedArticlesBitwiseAlgorithmsBitwiseOperatorsinC/C++PythonBitwiseOperatorsBitsmanipulation(Importanttactics)LittleandBigEndianMysterySmallestofthreeintegerswithoutcomparisonoperatorsFindthetwonon-repeatingelementsinanarrayofrepeatingelements/UniqueNumbers2WriteanEfficientCProgramtoReverseBitsofaNumberSmallestpowerof2greaterthanorequaltonHowtoswaptwobitsinagiveninteger?CopysetbitsinarangeGraytoBinaryandBinarytoGrayconversionKaratsubaalgorithmforfastmultiplicationusingDivideandConqueralgorithmComputetheparityofanumberusingXORandtablelook-upBooth’sMultiplicationAlgorithmFindthen-thnumberwhosebinaryrepresentationisapalindromeOptimizationTechniques|Set1(Modulus)BitFieldsinCWhatarethedifferencesbetweenbitwiseandlogicalANDoperatorsinC/C++?C++bitsetanditsapplicationC++bitsetinterestingfactsBuiltinfunctionsofGCCcompilerBitwiseAlgorithmsBitwiseOperatorsinC/C++PythonBitwiseOperatorsBitsmanipulation(Importanttactics)LittleandBigEndianMysterySmallestofthreeintegerswithoutcomparisonoperatorsFindthetwonon-repeatingelementsinanarrayofrepeatingelements/UniqueNumbers2WriteanEfficientCProgramtoReverseBitsofaNumberSmallestpowerof2greaterthanorequaltonHowtoswaptwobitsinagiveninteger?CopysetbitsinarangeGraytoBinaryandBinarytoGrayconversionKaratsubaalgorithmforfastmultiplicationusingDivideandConqueralgorithmComputetheparityofanumberusingXORandtablelook-upBooth’sMultiplicationAlgorithmFindthen-thnumberwhosebinaryrepresentationisapalindromeOptimizationTechniques|Set1(Modulus)BitFieldsinCWhatarethedifferencesbetweenbitwiseandlogicalANDoperatorsinC/C++?C++bitsetanditsapplicationC++bitsetinterestingfactsBuiltinfunctionsofGCCcompilerBitwiseOperatorsinC/C++ViewDiscussion
ImproveArticle
SaveArticle
LikeArticle
DifficultyLevel:
MediumLastUpdated:
27May,2022InC,thefollowing6operatorsarebitwiseoperators(workatbit-level) The&(bitwiseAND)inCorC++takestwonumbersasoperandsanddoesANDoneverybitoftwonumbers.TheresultofANDis1onlyifbothbitsare1. The|(bitwiseOR)inCorC++takestwonumbersasoperandsanddoesORoneverybitoftwonumbers.TheresultofORis1ifanyofthetwobitsis1. The^(bitwiseXOR)inCorC++takestwonumbersasoperandsanddoesXORoneverybitoftwonumbers.TheresultofXORis1ifthetwobitsaredifferent. The<>(rightshift)inCorC++takestwonumbers,rightshiftsthebitsofthefirstoperand,thesecondoperanddecidesthenumberofplacestoshift. The~(bitwiseNOT)inCorC++takesonenumberandinvertsallbitsofit. Example: C++#include
延伸文章資訊
- 1[ C 文章收集] Bitwise Operation - 程式扎記
接下來要介紹位元運算的一些用途. Bitwise operator 介紹: * << SHIFT LEFT , >> ...
- 2Bitwise Operators in C | GATE Notes - Byju's
- 3Bitwise operation - Wikipedia
In computer programming, a bitwise operation operates on a bit string, a bit array or a binary nu...
- 4Bitwise Operators in C [With Coding Example] | upGrad blog
- 5Understanding Bitwise Operators - Code
Bitwise operators are operators (just like +, *, &&, etc.) that operate on ints and uints at the ...