number of rounds is the same as the highest bit has in the byte-value that has a 1
ex:
11 = 00001011; 4th bit is set with means we will have 4 rounds
23 = 00010111; 5th bit is set -> 5 rounds
then it's "just" to write a nice procedure to calculate this...
PHP Code:
function highbit($a) {
$highbit = 0;
$bitcomp = 1;
for ($i=1; $i<16; $i++) {
if ($a & $bitcomp) {
$highbit = $i;
}
$bitcomp = $bitcomp << 1;
}
return $highbit;
}
this function works for up to 16384 players, if more needed, just change the value in the for-loop, from 16 to a higher value. Just put number of players as parameter to the function. highbit(57) would give 6 (max 64) and highbit(23) would give 5 (max 32)