7. A BIT of This AND That


A BIT of This AND That

Help, guys
my cod doesnt print anything. I want to figure out why. and find my mistakes. Ill aprisiate your any help



Is there a reason you are not using the & operator for this? You really only need one line.

But to answer your question why this doesn't print anything:

firstbin = 0b1110
secondbin = 0b101
strfirstbin = str(firstbin)
strsecondbin = str(secondbin)
lenf = len(strfirstbin)
lens = len(strsecondbin)
fbin2 = strfirstbin[2::]
sbin2 = strsecondbin[2::]

After you do this fbin2 and sbin2 are empty strings.

str(firstbin) gives you the string of the decimal representation not the binary one. That means strfirsbin[2::] is empty.
Same thing goes for the second number.

my_number = 0b100


my_number = 4

are both doing the same thing.

I think converting an integer to a string in binary representation is covered later in the course. But here you don't need any string at all.


ohh thnx very much... but now the new qwestion is appeare. http://pastebin.com/CjyMBAjR
its return 1011010 instead of 100


You put a lot of effort into this, but to be honest I don't really want to read through your code if you can just use:

print (0b1110 & 0b101)

The & operator is what this lesson is about after all, so why not use it?


I just wanna practice my skills


& is too easy, so I desided to do smth more complex


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