Of course, if you're using floating numbers and stuff, you're in trouble. Unless you use logarithms and type:
int(log(b)/log(2)) == log(b)/log(2)