-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path147.c
More file actions
41 lines (31 loc) · 709 Bytes
/
147.c
File metadata and controls
41 lines (31 loc) · 709 Bytes
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
41
#include<stdio.h>
unsigned int ToggleBit(unsigned int iNo,int iStart,int iEnd)
{
if(iStart<1||iStart>32||iEnd<1||iEnd>32)
{
return 0;
}
unsigned int iMask1=0xffffffff;
unsigned int iMask2=0xffffffff;
unsigned int iMask;
unsigned int Result=0;
iMask=iMask<<(iStart-1);
iMask=iMask>>(32-iEnd);
iMask=iMask1&iMask2;
Result=iNo ^ iMask;
return Result;
}
int main()
{
unsigned int iValue;
int iRet=0,iPos1=0,iPos2=0;
printf("Enter starting number\n");
scanf("%u",&iValue);
printf("enter the starting bit\n");
scanf("%d",&iPos1);
printf("enter the ending bit\n");
scanf("%d",&iPos2);
iRet=ToggleBit(iValue,iPos1,iPos2);
printf("Number after updation is %d\n",iRet);
return 0;
}