Bitwise operator in Python

       In this tutorial, you will learn about bitwise operator in python and bitwise operator examples. Operator is the symbol used to perform arithmetical and logical operations. Like other programming language python reserve some special characters acting as operators. Python language is rich in built in type of the operators. Operators are used to perform the operations of variables and characters.
       Operators are represented by operators and special characters.
       Variables passed as a input to the operator called as operands.
       Every operator carries out some operation like addition, multiplication to manipulate variable and data.
 The combination of data objects into expression is supported by python.
Meaning of the tokens + and -, and the use of parenthesis for grouping, is same in math’s and Python.

e.g to explain operators:-
       4+5=9, now in this example ‘4 ‘and ‘5’ are called operators.
       The Python operator types are as follows:-

  1. Arithmetic operators.
  2. Identity operators.
  3. Logical operators.
  4. Bitwise operators.
  5. Relational operator.
  6. Assignment operators.
  7. Membership operators.
  8. Precedence operators.

. Bitwise Operators:-
 It acts on operands as if they were string of binary digits. They operate bit by bit so name is bitwise. Bitwise operator has two operands and works on it bit by bit instead of whole. We will discuss python Bitwise AND, OR, XOR, Left-shift, Right-shift, and 1’s complement Bitwise Operators in Python In python programming all the decimal values are converted into sequence of bits i.e.0 and 1.  They work on bits such as shifting them left to right or converting value from 0 to 1.
 Bitwise operators are same in most languages that support them.

Bitwise operator example :
Value of 2 is “10” in binary and 7 is “111”.
  

In the table below:-

          Let x = 10 (0000 1010 in binary) and y = 4 (0000 0100 in binary)

Operator

Meaning

Example

&

Bitwise AND

x& y = 0 (0000 0000)

|

Bitwise OR

x | y = 14 (0000 1110)

~

Bitwise NOT

~x = -11 (1111 0101)

^

Bitwise XOR

x ^ y = 14 (0000 1110)

>> 

Bitwise right shift

x>> 2 = 2 (0000 0010)

<< 

Bitwise left shift

x<< 2 = 40 (0010 1000)

 

Additional Services : Refurbished Laptops Sales, Python Classes, Share Market Classes And SEO Freelancer in Pune, India