Wednesday, April 25, 2007

#34

How simple can your code be if you want to return the firs set/unset bits?
Answer:

    c & -c or c & (~c + 1); //Return first bit set
    ~c & (c + 1); //Return first unset bit

No comments: