Berkeley CSUA MOTD:Entry 12077
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/28 [General] UID:1000 Activity:popular
5/28    

2004/2/2-3 [Computer/SW/Languages/Perl] UID:12077 Activity:nil
2/2     Trivia of the day: what does this do?
        n = ((n >>  1) & 0x55555555) | ((n <<  1) & 0xaaaaaaaa);
        n = ((n >>  2) & 0x33333333) | ((n <<  2) & 0xcccccccc);
        n = ((n >>  4) & 0x0f0f0f0f) | ((n <<  4) & 0xf0f0f0f0);
        n = ((n >>  8) & 0x00ff00ff) | ((n <<  8) & 0xff00ff00);
        n = ((n >> 16) & 0x0000ffff) | ((n << 16) & 0xffff0000);
        \_ [formatd]
        \_ I'm just guessing, but possibly reverse the order of the bits in n.
                \_ um, are you sure it's O(n)? ARE YOU SURE???
                   \_ um, wtf are you responding to?
                      \_ um, he doesn't know!  he ISN'T SURE!
        \_ nothing interesting but if I cared I could run it through perl or
           wrap it in C syntax but I don't care.