View Single Post
  #7 (permalink)  
Old 08-28-2008, 06:58 AM
orjan's Avatar   
orjan orjan is offline
Programming Expert
 
Join Date: Sep 2007
Location: Sunne, Värmland, Sweden
Age: 33
Posts: 359
Last Blog:
Procedural Programming...
Credits: 42
Rep Power: 9
orjan has a spectacular aura aboutorjan has a spectacular aura aboutorjan has a spectacular aura about
Default Re: Tournament Generate

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)

Last edited by orjan; 08-28-2008 at 07:42 AM. Reason: Added an function
Reply With Quote