20120113

Program in C to manipulate bits,bitmanip.c

//========================
//Program in C to manipulate bits,bitmanip.c
//========================
#include<stdio.h>
int main()
{
int n,b;
printf("\n Enter a number and bit to manipulate: \n");
scanf("%d%d",&n,&b);
printf("You entered %d and %d",n,b);
//Code to Set bth bit in number n
n=n|(1<<b);
//to toggle //n=n^(1<<b)
//to display bth bit// n&(1<<b)
//to clear bth bit // n& ~(1<<b)
printf("\n Entered Number after setting %d th bit is %d \n :",b,n);
return 0;
}

No comments:

Post a Comment