11. the man behind the mask example question


#1



https://www.codecademy.com/en/courses/python-intermediate-en-KE1UJ/2/1?curriculum_id=4f89dab3d788890003000096#


hello!, i dont understand the whole example shown here, the example says:

num  = 0b1100
mask = 0b0100
desired = num & mask
if desired > 0:
    print "Bit was on"

"In the example above, we want to see if the third bit from the right is on."

i don't understand exactly from what point i have to start counting the third bit from the right, is it after the 0b or counting from the very beginning including the 0b

thanks for the answers



#2
0 b 0 1 0 0
0 b 1 1 0 0   <- from the right
    4 3 2 1
      ^

#3

ok, i get it now
is from the right of the very first bit(or last bit if you read from left to right), as if that first 0 was a person that is looking to me hehehe

my confusion is that i started counting from my right, that why i startet counting from 0b

thanks man!


#4

We always count bits from the right, as it is the lowest order bit.

     1   1   1   1   1   1   1   1
2 ** 7   6   5   4   3   2   1   0
    128  64  32  16  8   4   2   1

#5

ohhhh ok
i got it now


#6

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