sandeepkumar211221
BAN USER1 #include<stdio.h>
2
3 int find_1st_set_Bit_from_msb(int x,int mask,int count)
4
5 {
6
7
8 if( x & mask)
9
10 return count;
11
12 mask = mask >> 1;
13
14 find_1st_set_Bit_from_msb(x,mask,--count);
15
16
17 }
18
19 int main()
20
21 {
22
23 int count = sizeof(int)*8;
24
25 unsigned int size = sizeof(int)*8;
26
27 unsigned int mask = 1<<(size-1);
28
29
30
31 int x;
32
33 printf("Enter the Number :");
34
35 scanf("%d",&x);
36
37 int y=find_1st_set_Bit_from_msb(x,mask,count);
38
39 printf("1st msb position set 1 =%d",y);
40
41
42
43 }
1 #include<stdio.h>
2
3 int bitSet(int num,int pos)
4
5 {
6
7 if((num &(1<<(pos-1))))
8
9 return 1;
10
11 else
12 return 0;
13
14 }
15
16
17 int main()
18
19
20 {
21
22 int num,pos;
23
24 printf("Enter the Number ");
25
26 scanf("%d",&num);
27
28 printf("Enter the position :");
29
30 scanf("%d",&pos);
31
32 if(bitSet(num,pos))
33
34 printf("True");
35
36 else
37 printf("False");
38
39
40
41 }
1 #include<stdio.h>
2
3 void printBinary(int a)
4
5 {
6
7 unsigned int mask,bit,size;
8
9 size = sizeof(int)*8;
10
11 mask = 1 << size-1;
12
13 for(int i =0 ;i<size;i++)
14
15 {
16
17 bit = (a & mask) ? 1 : 0;
18
19 mask = mask >>1;
20
21 printf("%d ",bit);
22
23 }
24
25 printf("\n");
26
27 }
28
29 int setBit(int pos1 , int pos2,int num1,int num2)
30
31 {
32
33 int n = (pos2-pos1)+1;
34
35
36 return (num2 | (num1 &((1<<n)-1)<<(pos1-1)));
37
38 }
39
40 int main()
41
42 {
43
44 int num1,num2,pos1,pos2;
45
46 printf("Enter the 1st Number :");
47
48 scanf("%d",&num1);
49
50 printBinary(num1);
51
52 printf("Enter the 2nd Number :");
53
54 scanf("%d",&num2);
55
56 printBinary(num2);
57
58 printf("Enter the 1st position ");
59
60 scanf("%d",&pos1);
61
62 printf("Enter the 2nd position :");
63
64 scanf("%d",&pos2);
65
66 printBinary(setBit(pos1,pos2,num1,num2));
67
68 }
1 #include<stdio.h>
2
3 int main()
4
5 {
6
7 int x =1;
8
9 char *c = (char*)&x;
10
11 if(*c)
12
13 printf("Little endian");
14
15 else
16
17 printf("Big endian");
18
19 }
1 #include<stdio.h>
2
3 int implement_ternary_operator(int a,int b,int c)
4
5 {
6
7 return ((!!a)*b + (!a)*c);
8
9 }
10
11 int main()
12
13 {
14
15 int a = 1,b =10,c =20;
16
17 printf(" result = %d\n",implement_ternary_operator(a,b,c));
18
19 a=0;
20
21
22 printf(" result = %d",implement_ternary_operator(a,b,c));
23
24 }
1 #include<stdio.h>
2
3 int implement_ternary_operator(int a,int b,int c)
4
5 {
6
7 return ((!!a)*b + (!a)*c);
8
9 }
10
11 int main()
12
13 {
14
15 int a = 1,b =10,c =20;
16
17 printf(" result = %d\n",implement_ternary_operator(a,b,c));
18
19 a=0;
20
21
22 printf(" result = %d",implement_ternary_operator(a,b,c));
23
24 }
RepSarahSKelly, Game Programmer at Akamai
I am Professor, and I am also a skilled fiction writer. I have a collection of novels published in the ...
#include<stdio.h>
- sandeepkumar211221 December 11, 2020int swapBits(int x)
{
unsigned int even_bit=0xAAAAAAAA&x;
unsigned int odd_bit=0x55555555&x;
return (even_bit>>1)|(odd_bit<<1);
}
int main()
{
int x= 2555;
x= swapBits(x);
print("%d",x);
}