Back to index

lightning-sunbird  0.9+nobinonly
Functions
prlog2.c File Reference
#include "prbit.h"

Go to the source code of this file.

Functions

 PR_IMPLEMENT (PRIntn)

Function Documentation

PR_IMPLEMENT ( PRIntn  )

Definition at line 43 of file prlog2.c.

{
    PRIntn log2 = 0;

    if (n & (n-1))
       log2++;
    if (n >> 16)
       log2 += 16, n >>= 16;
    if (n >> 8)
       log2 += 8, n >>= 8;
    if (n >> 4)
       log2 += 4, n >>= 4;
    if (n >> 2)
       log2 += 2, n >>= 2;
    if (n >> 1)
       log2++;
    return log2;
}