7/14 can some one help me on "a bit of this and that"


#1

i don't understand how 15 = 00001111 so how do i do the bin thing???????????????????????????????????????????????????????


#2
It's like this:        0  0  0  0  1 1 1 1
                     -------------------------
index/exponents:       7  6  5  4  3 2 1 0

If there is 1 it means that this bit is set. If you look at the index you can see that bit 0, 1, 2 and 3 are set.
The base in this calculation is 2**exponent/index

We said that 0,1,2 and 3 are set.

We have to do this calculation:

            2**0 + 2**1 + 2**2 + 2**3 = ?
            -----------------------------
   Equal to: 1   +   2  +   4  +   8  = 15

#3

It's looking for something like this:

print bin (0b1110 | 0b101)

#4

print bin(0b1110 & 0b101)

Look back to the lesson where you counted to 12 (lesson 3 in binary representation. Top that up to 15 and you should see how it works.


#5

Thanks for that 0xmoonstar, a really helpful explanation


#6

good explanation..thanks :blush: