4. Assignment 4
#include<stdio.h>
void main()
{
int question;
printf("SurpriseTest3\n");
printf("Enter Question Number : ");
scanf("%d",&question);
switch(question)
{
case 1 :;
int a;
printf("Enter a number whose 3rd and 2nd bit are supposed to be set : ");
scanf("%d",&a);
a=a|(1<<3);
a=a|(1<<2);
printf("Final result : %d\n",a);
break;
case 2 :;
int b;
printf("Enter a number whose 0th and 5th bit are supposed to be set : ");
scanf("%d",&b);
b=b|(1<<0);
b=b|(1<<5);
printf("Final result : %d\n",b);
break;
case 3 :;
int c;
printf("Enter a number whose 3rd and 2nd bit are supposed to be clear : ");
scanf("%d",&c);
c=c&~(1<<2);
c=c&~(1<<3);
printf("Final result : %d\n",c);
break;
case 4 :;
int d;
printf("Enter a number whose 1st and 4th bit are supposed to be toggled : ");
scanf("%d",&d);
d=d^(1<<1);
d=d^(1<<4);
printf("Final result : %d\n",d);
break;
case 5:;
int num5;
printf("Enter a number whose 0th bit is supposed to be deleted : ");
scanf("%d",&num5);
num5=num5>>1;
printf("%d\n",num5);
break;
case 6 :;
int num6;
printf("Enter a number whose 0th,1st and 2nd bits are supposed to be deleted : ");
scanf("%d",&num6);
num6=num6>>3;
printf("%d\n",num6);
break;
case 7:;
int n1,num,pos=5;
printf("Enter a number whose 5th bit is supposed to be deleted : ");
scanf("%d",&num);
n1=num<<(32-pos);
n1=n1>>(32-pos);
num=num>>(pos+1);
num=num<<pos;
num=n1|num;
printf("After deleting the %d bit the result is %d \n",pos,num);
/*
int r0,r1,r2,r3,r4,r5,r6,r7,num;
printf("Enter a number whose 5th bit is supposed to be deleted : ");
scanf("%d",&num);
r0=num&1;
r1=(num>>1&1)*2;
r2=(num>>2&1)*4;
r3=(num>>3&1)*8;
r4=(num>>4&1)*16;
//r5=(num>>5&1);
r6=(num>>6&1)*32;
r7=(num>>7&1)*64;
num = r0+r1+r2+r3+r4+r6+r7;
printf("%d\n",num);
*/
break;
}
}
Comments
Post a Comment