mystr = '100000001010' mystr[-4:]
a=0xf b=Integer(a).binary();f=b[-2:]; c=sum(Integer(i) * (2^Integer(e)) for e, i in enumerate(f)) print c