diff --git a/Reversebits.cpp b/Reversebits.cpp new file mode 100644 index 00000000..1b9d78e8 --- /dev/null +++ b/Reversebits.cpp @@ -0,0 +1,16 @@ +long reverseBits(long n){ + int arr[32]={0}; + int bit; + for(int i=0;i<32;i++){ + bit=n%2; + arr[i]=bit; + n=n/2; + } + long long int ans=0; + int count=0; + for(int i=31;i>=0;i--){ + ans=ans+(arr[i]*pow(2,count)); + count++; + } + return ans; +}