-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdz5.cpp
More file actions
58 lines (51 loc) · 857 Bytes
/
dz5.cpp
File metadata and controls
58 lines (51 loc) · 857 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <math.h>
//dz5 binary operations
char calc(char a) {
for (int i = 0; i < 7; i++) {
char f = pow(2, i);
if ((f & a) != 0) {
printf("1");
}
else {
printf("0");
}
}
printf("\n");
return 0;
}
char common_un(char a, char b) {
char a1 = calc(a);
char a2 = calc(b);
char res = a&b;
char a3 = calc(res);
return res;
}
char invert(char a) {
printf("invert = ");
char res,res_1,sec_res;
res = ~a;
res_1 = ~a;
int v = 128;
for (int i = 1; i <= 8; i++)
{
if (res >= v)
{
printf("1");
res -= v;
}
else
printf("0");
v /= 2;
}
printf("\n");
return res_1;
}
int main() {
char a = 15;
char b = 1676;
char res1 = common_un(a, b);
char res2 = invert(b);
printf("\ncommon_in= %d\n", res1);
printf("\ninvert= %d\n", res2);
}