本帖最后由 CC2530 于 2011-6-3 13:07 编辑
https://bbs.21ic.com/icview-240248-1-1.html
作业题:
1.现有一串数据xxxxxxxx0123456789abcdef,知道其crc32结果为12345678,求xxxxxxxx是多少
2.现有一串数据01234567xxxxxxxx89abcdef,知道其crc32结果为12345678,求xxxxxxxx是多少
答案:
#include "uni_int.h"
#include <stdlib.h>
uint32 crc32l_update_byte(uint32 crc_in,uint8 data);
uint32 crc32l_update_word(uint32 crc_in,uint16 data);
uint32 crc32l_update_dword(uint32 crc_in,uint32 data);
uint32 crc32l_update_nibble(uint32 crc_in,uint8 data);
uint32 crc32l_dis_update_dword(uint32 crc_out,uint32 data);
uint32 crc32l_dis_update_word(uint32 crc_out,uint16 data);
uint32 crc32l_dis_update_byte(uint32 crc_out,uint8 data);
uint32 crc32l_dis_update_nibble(uint32 crc_out,uint8 data);
uint8 crc32l_calculate(uint32 crc_in,const uint8 *data,uint16 size);
volatile uint32 A;
volatile uint32 B;
int main(void)
{
A=0xFFFFFFFF;
A=crc32l_update_dword(A,0X12345678);
A=crc32l_dis_update_dword(A,0X12345678); //恢复初值
A=0xFFFFFFFF;
A=crc32l_update_word(A,0X1234);
A=crc32l_update_word(A,0X5678);
A=crc32l_dis_update_word(A,0X5678);
A=crc32l_dis_update_word(A,0X1234); //恢复初值
A=0xFFFFFFFF;
A=crc32l_update_byte(A,0X12);
A=crc32l_update_byte(A,0X34);
A=crc32l_update_byte(A,0X56);
A=crc32l_update_byte(A,0X78);
A=crc32l_dis_update_byte(A,0X78);
A=crc32l_dis_update_byte(A,0X56);
A=crc32l_dis_update_byte(A,0X34);
A=crc32l_dis_update_byte(A,0X12); //恢复初值
A=0xFFFFFFFF;
A=crc32l_update_nibble(A,0X1);
A=crc32l_update_nibble(A,0X2);
A=crc32l_update_nibble(A,0X3);
A=crc32l_update_nibble(A,0X4);
A=crc32l_update_nibble(A,0X5);
A=crc32l_update_nibble(A,0X6);
A=crc32l_update_nibble(A,0X7);
A=crc32l_update_nibble(A,0X8);
A=crc32l_dis_update_nibble(A,0X8);
A=crc32l_dis_update_nibble(A,0X7);
A=crc32l_dis_update_nibble(A,0X6);
A=crc32l_dis_update_nibble(A,0X5);
A=crc32l_dis_update_nibble(A,0X4);
A=crc32l_dis_update_nibble(A,0X3);
A=crc32l_dis_update_nibble(A,0X2);
A=crc32l_dis_update_nibble(A,0X1); //恢复初值
//作业:
//1.现有一串数据xxxxxxxx0123456789abcdef,知道其crc32结果为12345678,求xxxxxxxx是多少
A=0x12345678;
A=crc32l_dis_update_dword(A,0x89abcdef);
A=crc32l_dis_update_dword(A,0x01234567);
A=crc32l_dis_update_dword(A,0xFFFFFFFF); //得0x0D1AD0D8
//答xxxxxxxx是0D1AD0D8
//检验:
A=0xFFFFFFFF;
A=crc32l_update_dword(A,0x0D1AD0D8);
A=crc32l_update_dword(A,0x01234567);
A=crc32l_update_dword(A,0x89abcdef); //得0x12345678
//2.现有一串数据01234567xxxxxxxx89abcdef,知道其crc32结果为12345678,求xxxxxxxx是多少
A=0xFFFFFFFF;
A=crc32l_update_dword(A,0x01234567);
B=A; //保存结果
A=0x12345678;
A=crc32l_dis_update_dword(A,0x89abcdef);
A=crc32l_dis_update_dword(A,B); //得0x2D2F927A
//检验:
A=0xFFFFFFFF;
A=crc32l_update_dword(A,0x01234567);
A=crc32l_update_dword(A,0x2D2F927A);
A=crc32l_update_dword(A,0x89abcdef); //得0x12345678
//答xxxxxxxx是2D2F927A
while(1);
} |