#include<stdio.h>
#include<math.h>
int main()
{
int num,i,count0=0,count1=0;
printf("enter number \n");
scanf("%d",&num);
for(i=0;i<32;i++)
{
if(num &((pow(2,31))>>i))
count1++;
else
count0++;
}
printf(" the no. of 0's and 1's in the given number are %d %d",count0,count1);
}
mangalasadu
0
Newbie Poster
Recommended Answers
Jump to PostThe result of "pow(2,31)" is a double. You apply a bitshift operation on it, which is not possible. Replace
pow(2,31)
with
((unsigned int)pow(2,31))
and it should work.
You don't need pow to begin with though, you don't have to start from the …
All 3 Replies
Reply to this topic
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.