Programming with Python

⌘K
  1. Home
  2. Docs
  3. Programming with Python
  4. Variables, Expression and...
  5. Operators and Types of Op...
  6. Bitwise Operators

Bitwise Operators

  • Bitwise operators are used to compare (binary) numbers
  • Consider x = 2, y = 3

Example

x=2
y=3
print("x&y",x&y)
print("x|y",x|y)
print("x^y",x^y)
print("~x",~x)
print("x<<y",x<<y)
print("x>>y",x>>y)

Output

('x&y', 2)
('x|y', 3)
('x^y', 1)
('~x', -3)
('x<<y', 16)
('x>>y', 0)

Loading

Views: 4

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments