Operate on bitwise values Python 3


show more Operating on bitwise values provides you with in-depth training on Developer. Taught by Bill Weinman as part of the Python 3 Essential Training show less
please wait ...

Operating on bitwise values

Python also has a full set of bitwise operators for operating on binary values, and occasionally this comes in handy. It's a little bit difficult to show, because when you print a value, for example if I just say 5 here, it will print it in decimal. Even if I specify it in binary, if I say it 0b0101, which is a five, it still prints it in decimal. So I am going to write a little one-line function, and I'll call it b for printing binary values.

I am going to use a format string here, and we'll learn more about those in a later chapter. The format method of the string, like that, and now when I say b5 like that, it prints the binary value to 8 places. That's basically what that format string does inside the curly braces, the :08b, that prints out a binary value to 8 places.

So now we can look at the binary operators, and we can see what they do on a bitwise level. So, we are going to define a couple of values, and we will call them x and y. And x, we'll give it a couple of ...

Operating on bitwise values
Video duration: 3m 30s 6h 36m Beginner

Viewers:

Operating on bitwise values provides you with in-depth training on Developer. Taught by Bill Weinman as part of the Python 3 Essential Training

Subjects:
Developer Web
Software:
Python
Author:
please wait ...