The Man Behind the Bit Mask


#1

What is the problem in this code ?

def check_bit4(input):
    lst = bin(input)
    if lst[len(lst)-4]==1:
        return "on"
    else:
        return "off"

#2

@bitplayer43068,
Try it with

def check_bit4(input):
 lst = bin(input)
 print lst
 print lst[-4:-3]
 if lst[-4:-3]=="1":
   return "on"
 else:
   return "off"
print "================="
print "1 " + check_bit4(1)
print "================="
print "2 " + check_bit4(2)
print "================="
print "4 " + check_bit4(4)
print "================="
print "8 " + check_bit4(8)
print "================="
print "16 " + check_bit4(16)
print "================="

and found using google search
python slice site:stackoverflow.com
for instance
http://stackoverflow.com/questions/509211/explain-pythons-slice-notation


#3

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