Wednesday, April 25, 2007

#30

How can you round up to the next highest power of 2?

Answer:

    unsigned int v;
    v--;
    v = v >> 1;
    v = v >> 2;
    v = v >> 4;
    v = v >> 8;
    v = v >> 16;
    v++;

No comments: