본문 바로가기
알고리즘/leetcode

190. Reverse Bits

by 유이얼 2022. 7. 24.
class Solution {
public:
    uint32_t reverseBits(uint32_t n) {
        n = (n >> 16) | (n << 16);
        n = ((n & 0xff00ff00) >> 8) | ((n & 0x00ff00ff) << 8);
        n = ((n & 0xf0f0f0f0) >> 4) | ((n & 0x0f0f0f0f) << 4);
        n = ((n & 0xcccccccc) >> 2) | ((n & 0x33333333) << 2);
        n = ((n & 0xaaaaaaaa) >> 1) | ((n & 0x55555555) << 1);
        return n;
    }
};

 

'알고리즘 > leetcode' 카테고리의 다른 글

189. Rotate Array  (0) 2022.07.24
19. Remove Nth Node From End of List  (0) 2022.07.24
191. Number of 1 Bits  (0) 2022.07.24
231. Power of Two  (0) 2022.07.24
120. Triangle  (0) 2022.07.22