Computer Science, asked by prathyushathatipally, 10 months ago

write a c program to get minimum bits to store an integer value​

Answers

Answered by SJSURAJ
0

Explanation:

/*Program to get minimum number of bits to store an integer number.*/

#include <stdio.h>

/*function declaration

* name : countBit

* Desc : to get bits to store an int number

* Parameter : int

* return : int

*/

int countBit(int);

int main()

{

int num;

printf("Enter an integer number :");

scanf("%d",&num);

printf("Total number of bits required = %d\n",countBit(num));

return 0;

}

int countBit(int n)

{

int count=0,i;

if(n==0) return 0;

for(i=0; i< 32; i++)

{

if( (1 << i) & n)

count=i;

}

return ++count;

}

Answered by Anonymous
3

Hey mate don't WORRY about the answer....ok...because this qustion is in my book also ok...and I know it very well....don't think that I have copied it from anywhere...ok...because I amn't a cheater.....ok..

/*Program to get minimum number of bits to store an integer number.*/

#include <stdio.h>

/*function declaration

* name : countBit

* Desc : to get bits to store an int number

* Parameter : int

* return : int

*/

int countBit(int);

int main()

{

int num;

printf("Enter an integer number :");

scanf("%d",&num);

printf("Total number of bits required = %d\n",countBit(num));

return 0;

}

int countBit(int n)

{

int count=0,i;

if(n==0) return 0;

for(i=0; i< 32; i++)

{

if( (1 << i) & n)

count=i;

}

return ++count;

}

Hope this helps you...please mark me as Brainiest....AND please give mee a THANKS...also....

Similar questions