From d9b8bd61a500fd9bad0641aa599eb1689f4dd333 Mon Sep 17 00:00:00 2001 From: Udhay <72250606+Udhay-Brahmi@users.noreply.github.com> Date: Sat, 12 Dec 2020 09:17:16 +0530 Subject: [PATCH] Create Change the bits --- Change the bits | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Change the bits diff --git a/Change the bits b/Change the bits new file mode 100644 index 000000000..5396373d1 --- /dev/null +++ b/Change the bits @@ -0,0 +1,23 @@ +// { Driver Code Starts +//Initial Template for C++ + +#include <bits/stdc++.h> +using namespace std; + + // } Driver Code Ends + + +//User function Template for C++ + +class Solution { + public: + vector<int> changeBits(int N) { + // code here + vector<int> vec; + int y = floor(log(N)/log(2))+1; + int a = pow(2,y) - 1; + vec.push_back(abs(a-N)); + vec.push_back(a); + return vec; + } +};