-
Notifications
You must be signed in to change notification settings - Fork 222
/
bitwise-operators-in-c.c
51 lines (43 loc) · 1.03 KB
/
bitwise-operators-in-c.c
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
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define max(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
void calculate_the_maximum(int n, int k) {
int res = 0;
for (int i = 1; i < n; i++) {
for (int j = i+1; j < n+1; j++) {
int tmp = i & j;
if ((tmp < k) && (res < tmp))
res = tmp;
}
}
printf("%d\n", res);
res = 0;
for (int i = 1; i < n; i++) {
for (int j = i+1; j < n+1; j++) {
int tmp = i | j;
if ((tmp < k) && (res < tmp))
res = tmp;
}
}
printf("%d\n", res);
res = 0;
for (int i = 1; i < n; i++) {
for (int j = i+1; j < n+1; j++) {
int tmp = i ^ j;
if ((tmp < k) && (res < tmp))
res = tmp;
}
}
printf("%d\n", res);
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
calculate_the_maximum(n, k);
return 0;
}