def log2(x,ln2 = math.log(<NUM_LIT>)):
try:<EOL><INDENT>bin_n = binary_repr(x)[<NUM_LIT:1>:]<EOL><DEDENT>except (AssertionError,TypeError):<EOL><INDENT>return math.log(x)/ln2<EOL><DEDENT>else:<EOL><INDENT>if '<STR_LIT:1>' in bin_n:<EOL><INDENT>return math.log(x)/ln2<EOL><DEDENT>else:<EOL><INDENT>return len(bin_n)<EOL><DEDENT><DEDENT>
Return the log(*x*) in base 2.

This is a _slow_ function but which is guaranteed to return the correct
integer value if the input is an integer exact power of 2.