Yesterday, nobody contributed anything. :-( The official answer is: log2(floor(x * (x - 1))) - x + -1.