reverse-bits-v2.cpp (244B)
1 class Solution { 2 public: 3 int reverseBits(int n) { 4 int res = 0; 5 for(int i = 0; i < 32; ++i){ 6 int rem = n & 0b1; 7 n = n >> 1; 8 res += rem*(pow(2,31-i)); 9 } 10 return res; 11 } 12 };
algorithmsAlgorithm implementations | |
| git clone git://git.laack.co/algorithms.git | |
| Log | Files | Refs | README |