What if I want to compare bit strings of uneven length?


#1

Question

What if I want to compare bit strings of uneven length?

Answer

That’s totally fine! It will line them up accordingly (from the right) and fill in 0s for the leftmost unfilled bits. At least this is what you can do visually to help.
If we want to & together the bit strings 1001 and 1001 1010, for example, we would write it out like this:

  0000 1001
& 1001 1010
-------------
  0000 1000

FAQ: Learn Python - Introduction to Bitwise Operators - A BIT of This AND That