Can anyone tell me the best way to check the number of bits in a number ? for ex, in 2 set bits are1 , in 3 it is 2. So what is best way today available so as to get that value ? thanks. just give me link of algo, i wana code it myself. Give me hint or algo's link. thanks in advance.
I_m_rude
Recommended Answers
Jump to Post"Best" is subjective and dependent on the needs of the situation, but a concise and reasonable generic solution is this one:
int count_set_bits(int value) { int n = 0; while (value) { value &= value - 1; ++n; } return n; }
The benefit of this …
Jump to Posthow do you come to know about these types of links which you have given above ?
Programming is my hobby as well as my job, so I do a lot of reading on the subject. It should go without saying that I'll encounter interesting texts and web …
Jump to Postin other words, You are genius.
Absolutely not. I make up for lack of talent and average intelligence with heaps of effort.
haven't you done codechef, spoj like online judges in your school or university time ?
I'm not a fan of code competitions. Not only …
All 10 Replies
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
I_m_rude
commented:
very nice explained! ;)
+2
I_m_rude
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
I_m_rude
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
I_m_rude
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
I_m_rude
neeratyoy.mallik
0
Newbie Poster
I_m_rude
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.