-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathxtime.cpp
More file actions
117 lines (57 loc) · 1.24 KB
/
Copy pathxtime.cpp
File metadata and controls
117 lines (57 loc) · 1.24 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include<stdio.h>
unsigned char XTIME(unsigned char x);
unsigned char multiply(unsigned char a, unsigned char b);
int exchange(int x);
#define N 8
int main()
{
unsigned char z;
int a,b;
printf("请输入两个16进制数:");
scanf("%x %x",&a,&b);
z=multiply(a,b);
printf("十六进制乘法表示:");
printf("%x*%x=",a,b);
printf("%x\n",z);
printf("二进制的乘法表示:");
exchange(a);
printf("*");
exchange(b);
printf("=");
exchange(z);
printf("\n");
return 0;
}
int exchange(int x)
{
int i,A[N];
for(i=0;i!=N;i++)
{
A[N-1-i]=x%2;
x/=2;
}
for(i=0;i!=N;i++)
{
printf("%d",A[i]);
}
return 0;
}
unsigned char XTIME(unsigned char x)
{
return ((x << 1) ^ ((x& 0x80) ? 0x1b : 0x00));
}
unsigned char multiply(unsigned char a, unsigned char b)
{
unsigned char temp[8] = { a};
unsigned char tempmultiply =0x00;
int i = 0;
for (i = 1; i < 8; i++) {
temp[i] = XTIME(temp[i -1]);
}
tempmultiply = (b & 0x01) *a;
for (i = 1; i <= 7; i++)
{
tempmultiply ^= (((b >>i) & 0x01) * temp[i]);
}
return tempmultiply;
}