Showing posts with label Number of bits required to rpresents the integer value. Show all posts
Showing posts with label Number of bits required to rpresents the integer value. Show all posts

Wednesday, March 23, 2011

Number of bits required to rpresents the integer value

# include "stdio.h"
int fnIntegerbit(int);
int main()
{
int nNumber;
printf("Enter the number which you want to know the number of bit representation \n");
scanf("%d",&nNumber);

printf("Required number of Bits: %d\n",fnIntegerbit(nNumber));

return 0;
}

int fnIntegerbit(int nNumber)
{

int nSum=1;
int nLoop=0;
while(nSum <= nNumber)
{
nSum += nSum;
nLoop++;

}
return nLoop;



}


OUTPUT:

Enter the number which you want to know the number of bit representation
128
Required number of Bits: 8
Press any key to continue . . .