crc.c

来自「CRC校验程序」· C语言 代码 · 共 49 行

C
49
字号
#define CRC_POLY 0x25
//unsigned int CRC_POLY 0x9240;
union WordUnion
{
	struct
	{
		unsigned char lowbyte;
		unsigned char highbyte;
	}twobyte;
	unsigned int word;
};

main()
{
	union WordUnion TempWord;
	unsigned char i,lowbyte,highbyte;
        highbyte=0x70;
        lowbyte=0x00;
	TempWord.twobyte.lowbyte =lowbyte;
	TempWord.twobyte.highbyte =highbyte;
	for ( i=0 ; i<16; i++)
	{
		if (TempWord.twobyte.highbyte & 0x80)
		{
			//TempWord.word <<= 1;
                        TempWord.twobyte.highbyte <<= 1;
                        if(TempWord.twobyte.lowbyte & 0x80)
                        {
                                TempWord.twobyte.highbyte|=0x01;
                        }
                        TempWord.twobyte.lowbyte<<=1;
			TempWord.twobyte.highbyte ^= CRC_POLY;
		}
		else
                {
			TempWord.twobyte.highbyte <<= 1;
                        if(TempWord.twobyte.lowbyte & 0x80)
                        {
                                TempWord.twobyte.highbyte|=0x01;
                        }
                        TempWord.twobyte.lowbyte<<=1;

                }
	}
	TempWord.twobyte.highbyte=TempWord.twobyte.highbyte;
        i=TempWord.twobyte.highbyte;
        i=TempWord.twobyte.lowbyte;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?