From 3715dc70c888a62e126744419b27789fd1fac1f2 Mon Sep 17 00:00:00 2001 From: Khushboo741 <116384371+Khushboo741@users.noreply.github.com> Date: Tue, 24 Oct 2023 17:31:36 +0530 Subject: [PATCH] Create Reversebits.cpp --- Reversebits.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Reversebits.cpp 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; +}