Liberation.绯世 2021-11-20 19:27 采纳率: 0%
浏览 12

代码不知道每一行的作用,希望能注释一下

#include<iostream>
#include<cstring>
using namespace std;
unsigned int Fun(unsigned char* buffer, int size)
{
    unsigned int x = 1;
    unsigned int p = x + (x << 1) + (x << 2) + (x << 4) + (x << 5) + (x << 7) + (x << 8) + (x << 10) + (x << 11) + (x << 12) + (x << 16) + (x << 22) + (x << 23) + (x << 26);
    unsigned int crc = 0;
    unsigned int now = 0;
    for (int i = 0; i < size; i++)
    {
        for (int j = 7; j >= 0; j--)
        {
            unsigned int q = 0;
            if ((now >> 31) & (unsigned int)1) q = p;
            now = (now << 1) | ((buffer[i] >> j) & (unsigned int)1);
            now = (now ^ q);
            crc = now;
        }
    }
    return crc;
}
int main() {
    unsigned char* a = new unsigned char[10];
    cin >> a;
    cout << Fun(a, strlen((const char*)a));
    return 0;
}

  • 写回答

1条回答 默认 最新

  • CSDN专家-Time 2021-11-20 19:31
    关注

    <<是左移,>> 是右移,其他都是调用函数。
    有一个for循环。
    include是导入c++本地库。

    评论

报告相同问题?

问题事件

  • 创建了问题 11月20日

悬赏问题

  • ¥15 请各位帮我看看是哪里出了问题
  • ¥15 vs2019的js智能提示
  • ¥15 关于#开发语言#的问题:FDTD建模问题图中代码没有报错,但是模型却变透明了
  • ¥15 uniapp的h5项目写一个抽奖动画
  • ¥15 TeleScan不能修改bar
  • ¥100 请问我基于逐飞库写的这个有关于mp u6050传感器的函数,为什么输出的值是固定的?
  • ¥15 hadoop中启动hive报错如下怎么解决
  • ¥15 如何优化QWebEngineView 加载url的速度
  • ¥15 关于#hadoop#的问题,请各位专家解答!
  • ¥15 如何批量抓取网站信息