Sunday 2 October 2022

What is Bitwise Operator in C++, C Language|BITWISE OPERATOR in C++ |Bitwise Operator in Programming Language |Bitwise Operator in Computer Language |Bitwise Operator in C language, C++ |What is Operator in programming Language |Types of Operators in Programming Language |Types of Operators in C Language, C++

 - :  Bitwise Operator :-


    Operators are those symbols which are used between operands to perform Mathematical and Logical operations. 


    Bitwise Operators are those operators which are used to perform operations on integer values at the bit-level. This Operator includes Following Symbols - 

  • Bitwise And  [&] 
  • Bitwise Or  [|] 
  • Bitwise XOR  [^] 
  • Bitwise Complement Operator [~] 
  • Bitwise Left Shift Operator [<<] 
  • Bitwise Right Shift Operator [>>] 

    When we execute a program using Bitwise Operators. in this case first of all, the given Decimal Variables get converted into binary format and operation takes place between those converted binary numbers according to the symbol used. After performing operation whatever result comes in binary format, simply converted into decimal format and displayed on the screen. 

  1. Bitwise And (&) operator :- 
           if Both operands are "1", the output will be "1".if anyone of them is "0",the output will be "0".

  A                 B                      Output 
1                       1                           1      
    1                       0                           0          
0                       1                           0      
0                       0                           0      
For Example
let  A    = 10 (in Decimal)    =   1010 (in Binary) 
      B    = 14 (in Decimal)    =  1110 (in Binary)
                                             __________________
                                    1000 (in Binary)  = 8 (in Decimal) 

2. Bitwise Or ( | ) Operator :-

          if atleast one operand is "1", the output will be "1". if both operands are "0",the output will be "0".

                                    A         |            B                       Output 

 1                        1                            1      

    1                        0                            1          

0                        1                            1      

0                        0                            0      

For Example

       let A = 10 (in Decimal) = 1010 (in Binary) 

             B = 14 (in Decimal) = 1110 (in Binary)

                                            ___________________

                                                1110 (in Binary) = 14 (in Decimal) 


3. Bitwise XOR (^) Operator :-

           when both operators are "1 - 1" or "0 - 0", it return "0" in the Output. If both operators are not same then the output will be "1".

                                       A           ^              B                        Output 

 1                         1                             0      

    1                         0                             1          

0                         1                             1      

0                         0                             0      

For Example - 

       let A = 10 (in Decimal) = 1010 (in Binary) 

             B = 14 (in Decimal) = 1110 (in Binary)

                                            ___________________

                                              0100 (in Binary) = 4 (in Decimal) 


4. Bitwise Complement (~) Operator :- 

         it is a unary operator (works only on single operand). it converts "1" into "0" where "0" into 1.

          A                     ~A

           1                      0

           0                      1


5. Bitwise Right Shift (>>) Operator :-

        This Operator Shifts all the bits towards right hand side by the specified number of positions in bits. (eg. >>1means 1 bits, >>2 means 2 bits, >>3 means 3 bits and so on  towards right hand side.) 

       On shifting specified bits right hand side, Left bits will be vacant. These Vacant place will be filled by "0" automatically. 


6. Bitwise Left Shift (<<) Operator :-

         This Operator Shifts all the bits towards left hand side by the specified number of positions in bits. (eg. >>1means 1 bits, >>2 means 2 bits, >>3 means 3 bits and so on toward left hand side.) 

        On shifting specified bits left hand side, right bits will be vacant. These Vacant place will be filled by "0" automatically. 


__________________________________________________________

Must Read :- 

What is Operator in Programming Language 


What is Arithmetic Operator in Programming Language 


What is Relational Operator in C, C++ programming languages 


What is Logical Operators in C, C++ Programming  Language (English Explanation) 


What is Logical Operator in C, C++ Language (Hindi Explanation) 







No comments:

Post a Comment