• Profile
  • Resume
  • Portfolio
  • Blog
Avatar

Nelson Silva

A human. Being. Coffee lover.

Blog

I Write My Thoughts Here

Bitwise Operators in Python

November 2, 2021 Python

In this post, you will learn how to work with bitwise operators so that you can use that same knowledge and thus evolve.

  • bitwise operators operate one bit at a time and having a sense of what the binary code is is important;
1 True
0 False
& Only true when both numbers match 1 and 1
| It is only false when both numbers match 0 and 0
<< Shift bits according to given number to the left
>> Shift bits according to given number to the right
  • then we also have the operators ^ and ~;
  • such operators are mostly used in low-level applications for communication between networks and telecommunications.
x = 60 # 00111100
y = 13 # 00001101

print('Result of operator &:', x & y) # Result of operator &: 12 (00001100)
print('Result of operator |:', x | y) # Result of operator |: 61 (00111101)
print('Result of operator <<:', x << 2) # Result of operator <<: 240 (11110000)
print('Result of operator >>:', x >> 2) # Result of operator >>: 15 (00001111)

Don’t forget to watch the video and you can always read this post in Portuguese.

Happy coding!

Previous Next

Categories

  • Announcements
  • Python
  • C#
  • Java
  • Go

Latest Posts

  • for Loop in Go
    May 5, 2022
  • Switch in Go
    May 4, 2022
  • Comparison Operators in Go
    May 3, 2022
+351913416022
contact@nelsonsilvadev.com
Porto, Portugal
Nelson Silva © 2022 All Rights Reserved