A doubt in Python free course


#1

Can someone help me with this topic? its really confusing…
Python Lesson - Introduction to BitWise. A BIT of This AND That
I don’t really understand what is going on in this lesson.


#2

A BIT of This AND That

Bitwise refers to binary number operations that apply to 32-bit sequences, one of which is the sign bit (1 for negative, 0 for positive).

in an AND operation, bits of the same order (degree) are compared. If they are both the same, the resulting value will have that bit set; if not the same, the bit is set to zero.

0b101 & 0b10 => 0

0b101 & 0b11 => 1

In the first example, 5 and 2 do not have any bits in common. In the second, 5 and 3 have the 1’s bit in common.

Study the example in the lesson text. See how a & b has bit-2 and bit-4 set, and all the other bits are zero. Notice how in those columns they both have a 1?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.