From f27244f86a05a6b4559107cc54d57a1cec6d8c02 Mon Sep 17 00:00:00 2001 From: KillerAV Date: Fri, 8 Oct 2021 17:25:32 +0530 Subject: [PATCH] count_bits.cpp This code helps us in calculation of number of set and unset bits in a number. --- src/count_bits.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/count_bits.cpp diff --git a/src/count_bits.cpp b/src/count_bits.cpp new file mode 100644 index 00000000..292e7ba4 --- /dev/null +++ b/src/count_bits.cpp @@ -0,0 +1,25 @@ +#include +#define mod 1000000007 +#define ll long long +using namespace std; + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + int N; + cin>>N; + int oneCount=0,zeroCount=0; + while(N){ + if(N%2==1) + oneCount++; + else + zeroCount++; + N/=2; + } + cout<<"Count of number of set BITS: "<