-
Notifications
You must be signed in to change notification settings - Fork 2
/
bitwise-operators-in-c.c
61 lines (55 loc) · 1.74 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
52
53
54
55
56
57
58
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bitwise-operators-in-c.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ablaamim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/15 21:17:08 by ablaamim #+# #+# */
/* Updated: 2022/01/15 21:17:10 by ablaamim ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void calculate_the_maximum(int n, int k)
{
int i;
int j;
int max_and;
int max_or;
int max_xor;
max_and = 0;
max_or = 0;
max_xor = 0;
i = 1;
while (i <= n)
{
j = i + 1;
while (j <= n)
{
int x = i & j;
int y = i | j;
int z = i ^ j;
if(x < k & x > max_and)
max_and = x;
if(y < k & y > max_or)
max_or = y;
if(z < k & z > max_xor)
max_xor = z;
j++;
}
i++;
}
printf("%d\n%d\n%d", max_and, max_or, max_xor);
}
int main(int argc, char **argv)
{
(void) argc;
(void) argv;
int n;
int k;
scanf("%d %d", &n, &k);
calculate_the_maximum(n, k);
return (EXIT_SUCCESS);
}