- #include <stdio.h>
- #include <string.h>
- unsigned int crc_table[256];
- void generate_crc_table() {
- unsigned int crc, i, j;
- for (i = 0; i < 256; i++) {
- crc = i;
- for (j = 0; j < 8; j++) {
- if (crc & 0x01)
- crc = (crc >> 1) ^ 0xEDB88320;
- else
- crc >>= 1;
- }
- crc_table[i] = crc;
- }
- }
- unsigned int calculate_crc(const unsigned char *data, unsigned int length) {
- unsigned int crc = 0xFFFFFFFF;
- unsigned int i;
- for (i = 0; i < length; i++) {
- crc = (crc >> 8) ^ crc_table[(crc ^ data[i]) & 0xFF];
- }
- return ~crc;
- }
- int main() {
- char binaryString1[100];
- char binaryString2[100];
- printf("Enter the first binary string: ");
- scanf("%s", binaryString1);
- printf("Enter the second binary string: ");
- scanf("%s", binaryString2);
- // Calculate CRC for binaryString1
- generate_crc_table();
- unsigned int crc1 = calculate_crc((const unsigned char*)binaryString1, strlen(binaryString1));
- // Calculate CRC for binaryString2
- generate_crc_table();
- unsigned int crc2 = calculate_crc((const unsigned char*)binaryString2, strlen(binaryString2));
- printf("CRC of binaryString1: %08X\n", crc1);
- printf("CRC of binaryString2: %08X\n", crc2);
- return 0;
- }
[text] Cn1
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: