Program to check logical operations_3(set,clear bits in a particular number)
#include<stdio.h> main() { int choice,num,bit; printf("enter a num and bit\n"); scanf("%d%d",&num,&bit); printf("enter any choice\n"); scanf("%d",&choice); switch(choice) { case 1: printf("set bit\n"); num=num|(1<<bit); printf("number is %d",num); break; case 2: printf("clear bit\n"); num=num&~(1<<bit); printf("number is %d",num); break; case 3: printf("complement bit\n"); num=num^(1<<bit); printf("number is %d",num); break; case 4: printf("test bit\n"); num&(1<<bit)?printf("set"):printf("clear"); break; case 5: printf("exit"); break; default: printf("eneter currect choice\n"); } //printf("number is %d",num); }OutPut:
madan@madan-Lenovo-G570:~/madan$ cc ex45.c madan@madan-Lenovo-G570:~/madan$ ./a.out enter a num and bit 32 4 enter any choice 2 clear bit number is 32