Doesn't understand task 8/14


#1

I don't understand this fragment: "Try to do it on your own without using the | operator if you can help it."
My code is print bin(0b1110 | 0b101) and this of course works, but how to do it without |?


#2

Maybe

 print bin(0b1110 + 0b1)

#4

I'm kind of confused why they would ask it, since its a bit more difficult than your standard exercises (unless I missed the easy way). You should be able to do it though with all the knowledge you gained from previous exercises. Here's the example how I did it;

a = '0b1110'
b = '0b101'

def remove_0b(text):
    return text[2:]


def or_operator(x,y):
    #remove 0b from string
    x = remove_0b(x)
    y = remove_0b(y)
    z = ''
    #check for difference in length strings and equalize
    if len(x) > len(y):
        y = (len(x)-len(y))*'0'+y
    elif len(y) > len(x):
        x = (len(y)-len(x))*'0'+x
    #go through both strings and create result of or    
    for i in range(0,len(x)):
        if x[i]=='1' or y[i]=='1':
            z += '1'
        else:
            z+= '0'
    #change z to proper format again
    z = '0b'+z
    return z

print or_operator(a,b)

#5

I was thinking they meant to try it yourself on paper before running the code in the console, based on the rules they described for each bitwise operator (lesson 7, 8, and 9 are similar).