-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha1_p7.c.save
40 lines (38 loc) · 876 Bytes
/
a1_p7.c.save
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<stdio.h>
void setswitchbits(unsigned int uint,unsigned int fbit,unsigned sbit)
{
int s=32768, i;
unsigned int temp1, temp2, r;
temp1= uint;
; //temp1 |= 1UL << fbit temp1 = temp1 & ~(1 << (fbit))
temp2=temp1;
temp2=temp1 ^= 1UL <<(sbit);
printf("After setting and switching: ");
for(i=0;i<16;i++)
{
r=(temp2&s)>>(15-i);
printf("%u",r&1);
s>>=1;
}
}
int main()
{
unsigned int uint, fbit, sbit;
int i,s;
unsigned int r;
s=32768;
scanf("%u",&uint);
scanf("%u", &fbit);
scanf("%u", &sbit);
printf("The binary representation is: ");
for(i=0;i<16;i++)
{
r=(uint&s)>>(15-i);
printf("%u",r&1);
s>>=1;
}
printf("\n");
setswitchbits(uint,fbit,sbit);
printf("\n");
return 0;
}