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 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