Give a very good method to count the number of ones in a "n"
(e.g. 32) bit number.
Answers were Sorted based on User's Feedback
Answer / sujan
#define bit 32
using namespace std;
int bitConvert(int n)
int countBit(int a)
cout<<"Enter the no:";
cout<<"\n"<<"BitConversion of "<<n<< "is:";
cout<<"\n"<<"No. of bit:";
|Is This Answer Correct ?||4 Yes||1 No|
Answer / artyom
// It's still O(n), maybe there are better ways.
int countBit(int num)
int count = 0;
count += static_cast<int>(static_cast<bool>(mask &
num >>= 1;
|Is This Answer Correct ?||2 Yes||0 No|
Answer / manish kumar
for (c = 0; n; c++)
n &= n - 1;
Result: the value of c.
|Is This Answer Correct ?||1 Yes||0 No|
Write a program to calculate the BMI of a person using the formula BMI = weight/height2.
What is a parameterized type?
Explain the static storage classes in c++.
how to access grid view row?
Can a new be used in place of old mallocq? If yes, why?
What is a stack? How it can be implemented?
What is the difference between passing by reference and passing a reference?
Write a program to calculate the following i want a c++program for this condition 1+4+9+16+….+100 Like this (1^2+2^2) Hint use function pow(a,b)
What is the handle class?
Differentiate between the message and method in c++?
What is a catch statement?
What does extern mean in a function declaration in c++?