How to Count number of 1's in binary representation By Md. Babul Hasan (NoYoN) 15 May, 2020 Post a Comment Number Of bits in Binary form trick STL (c++): __builtin_popcount ( number ); //it will return number of 1's Other Method: while(n>0) { n = n & (n-1); count++; } Another Method: while(n) { count+= n & 1; n = n >> 1; } Share You may like these postsProblem Set of ICPC 2019 -(ICPC ASIA WEST CONTINENT FINAL CONTEST 2019)MOCK OF ICPC DHAKA REGIONAL 2020 ONLINE PRELIMINARYProblem Set of NCPC 2020How to convert String to Integer && Integer to String No comments for "How to Count number of 1's in binary representation"
No comments for "How to Count number of 1's in binary representation"
Post a Comment