-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog1.c
More file actions
63 lines (55 loc) · 1.28 KB
/
Copy pathprog1.c
File metadata and controls
63 lines (55 loc) · 1.28 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
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int8_t max = -128;
int8_t min = 127;
void hamming_distance()
{
int8_t num1 = 0b10101010;
int8_t num2 = 0b11111111;
int8_t num3 = 0b00000000;
int8_t arr[16] = {
0b00000000,
0b00001011,
0b00010101,
0b00011110,
0b00100110,
0b00101101,
0b00110011,
0b00111000,
0b01000111,
0b01001100,
0b01010010,
0b01011001,
0b01100001,
0b01101010,
0b01110100,
0b01111111,
};
uint8_t size = 16;
for (int i = 0; i < size; i++)
{
for (int j = i + 1; j < size; j++)
{
int8_t a = arr[i];
int8_t b = arr[j];
int8_t x = a ^ b;
int8_t distance = 0;
while (1)
{
if (x == 0) break;
distance = distance + (x & 1);
x >>= 1;
}
// update max and min
if (distance > max) max = distance;
if (distance < min) min = distance;
}
}
}
int main()
{
hamming_distance();
printf("Hamming distance max is %u and Hamming distance min is %u", max, min);
return 0;
}