Tuesday 24 July 2012

print the bit pattern of a 16 bit integer

/* How to write Program for printing the bit pattern of a 16 bit integer with comments*/

//declaring function bit(int)

void bit(int);

void main()

{

int val;

printf("Enter the value of integer to print its bit pattern:\n");

scanf("%d",&val);



printf("The bit pattern for integer %d is\n",val);

//printing binary pattern requires the testing of each bit

//so we will test each bit starting from the 15th bit till we reach to left

//this will be achieved by bit(val) function

bit(val);

}

void bit(int n)

{

int i,m;



for(i=15;i<=0;i--)

{



//testing ith bit

//testing ith bit requires masking

//the masking is done through 1<

m=1<



if((n&m)==0)

{

printf("0");

}

else

{

printf("1");

}

}

}
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: