Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
11
Task/CRC-32/C/crc-32-1.c
Normal file
11
Task/CRC-32/C/crc-32-1.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <zlib.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
const char *s = "The quick brown fox jumps over the lazy dog";
|
||||
printf("%lX\n", crc32(0, (const void*)s, strlen(s)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
48
Task/CRC-32/C/crc-32-2.c
Normal file
48
Task/CRC-32/C/crc-32-2.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
uint32_t
|
||||
rc_crc32(uint32_t crc, const char *buf, size_t len)
|
||||
{
|
||||
static uint32_t table[256];
|
||||
static int have_table = 0;
|
||||
uint32_t rem;
|
||||
uint8_t octet;
|
||||
int i, j;
|
||||
const char *p, *q;
|
||||
|
||||
/* This check is not thread safe; there is no mutex. */
|
||||
if (have_table == 0) {
|
||||
/* Calculate CRC table. */
|
||||
for (i = 0; i < 256; i++) {
|
||||
rem = i; /* remainder from polynomial division */
|
||||
for (j = 0; j < 8; j++) {
|
||||
if (rem & 1) {
|
||||
rem >>= 1;
|
||||
rem ^= 0xedb88320;
|
||||
} else
|
||||
rem >>= 1;
|
||||
}
|
||||
table[i] = rem;
|
||||
}
|
||||
have_table = 1;
|
||||
}
|
||||
|
||||
crc = ~crc;
|
||||
q = buf + len;
|
||||
for (p = buf; p < q; p++) {
|
||||
octet = *p; /* Cast to unsigned octet. */
|
||||
crc = (crc >> 8) ^ table[(crc & 0xff) ^ octet];
|
||||
}
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
const char *s = "The quick brown fox jumps over the lazy dog";
|
||||
printf("%" PRIX32 "\n", rc_crc32(0, s, strlen(s)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue