mirror of
git://projects.qi-hardware.com/wernermisc.git
synced 2024-12-04 21:01:54 +02:00
bitcmp/bitcmp.c: added indication of direction of bit flip (1 -> 0 or 0 -> 1)
This commit is contained in:
parent
78d9fda12f
commit
dd0c4ec3f9
@ -43,9 +43,9 @@ int main(int argc, char *const *argv)
|
|||||||
const char *name1, *name2;
|
const char *name1, *name2;
|
||||||
uint8_t buf1[BUFFER], buf2[BUFFER];
|
uint8_t buf1[BUFFER], buf2[BUFFER];
|
||||||
ssize_t got1, got2, len;
|
ssize_t got1, got2, len;
|
||||||
uint32_t diff;
|
uint32_t a, b;
|
||||||
int i, j;
|
int i, j;
|
||||||
static unsigned bin[32];
|
static unsigned bin[32][2];
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "Blw")) != EOF) {
|
while ((c = getopt(argc, argv, "Blw")) != EOF) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@ -92,24 +92,28 @@ int main(int argc, char *const *argv)
|
|||||||
if (!len)
|
if (!len)
|
||||||
break;
|
break;
|
||||||
for (i = 0; i < len; i += bytes) {
|
for (i = 0; i < len; i += bytes) {
|
||||||
diff = 0;
|
a = b = 0;
|
||||||
switch (bytes) {
|
switch (bytes) {
|
||||||
case 4:
|
case 4:
|
||||||
diff |= (buf1[i+2] ^ buf2[i+2]) << 16;
|
a |= buf1[i+2] << 16;
|
||||||
diff |= (buf1[i+3] ^ buf2[i+3]) << 24;
|
b |= buf2[i+2] << 16;
|
||||||
|
a |= buf1[i+3] << 24;
|
||||||
|
b |= buf2[i+3] << 24;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 2:
|
case 2:
|
||||||
diff |= (buf1[i+1] ^ buf2[i+1]) << 8;
|
a |= buf1[i+1] << 8;
|
||||||
|
b |= buf2[i+1] << 8;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 1:
|
case 1:
|
||||||
diff |= buf1[i] ^ buf2[i];
|
a |= buf1[i];
|
||||||
|
b |= buf2[i];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
for (j = 0; j != 32; j++)
|
for (j = 0; j != 32; j++)
|
||||||
if (diff & (1 << j))
|
if ((a ^ b) & (1 << j))
|
||||||
bin[j]++;
|
bin[j][(b >> j) & 1]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,8 +122,8 @@ int main(int argc, char *const *argv)
|
|||||||
i = j;
|
i = j;
|
||||||
else
|
else
|
||||||
i = 8*(bytes-1-(j >> 3))+(j & 7);
|
i = 8*(bytes-1-(j >> 3))+(j & 7);
|
||||||
if (bin[i])
|
if (bin[i][0] || bin[i][1])
|
||||||
printf("%2d: %u\n", j, bin[i]);
|
printf("%2d: %u %u\n", j, bin[i][0], bin[i][1]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user