0

我尝试使用 C++进行CRC 计算。因为它看起来很基本,所以我想用数组来做。

这是我的代码(低效且无意义):

/*3-bit CRC Calculator in C++*/
#include <iostream>

using namespace std;

int main()
{
    int m[100][100]; //Array to perform calculations... store values..
    int x = 4;
    m[1][0] = 1;
    m[1][1] = 0;
    m[1][2] = 1;
    m[1][3] = 1;

    cout << "Enter the binary sequence (14 digits):\n";

    cin >> m[0][x-4];
    cin >> m[0][x-3];
    cin >> m[0][x-2];
    cin >> m[0][x-1];
    cin >> m[0][x];
    cin >> m[0][x+1];
    cin >> m[0][x+2];
    cin >> m[0][x+3];
    cin >> m[0][x+4];
    cin >> m[0][x+5];
    cin >> m[0][x+6];
    cin >> m[0][x+7];
    cin >> m[0][x+8];
    cin >> m[0][x+9];

    m[0][x+10] = 0; //3-bit crc
    m[0][x+11] = 0;
    m[0][x+12] = 0;

    while (x >= -4){
        m[2][0] = m[0][0] xor m[1][0]; //Subraction from message binary code
        m[2][1] = m[0][1] xor m[1][1];
        m[2][2] = m[0][2] xor m[1][2];
        m[2][3] = m[0][3] xor m[1][3];

        m[0][0] = m[2][1];
        m[0][1] = m[2][2];
        m[0][2] = m[2][3] ;
        x--;
    }
    cout << "CRC Value: " << m[0][0] << m[0][1] << m[0][2];
    cin >> x;
    return 0;
}

现在它返回 110。:/

4

0 回答 0