基本信息
源码名称:CRC校验码计算
源码大小:0.49M
文件格式:.rar
开发语言:Pascal
更新时间:2016-12-08
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 1 元 
   源码介绍
CRC校验码计算

Type
  TcrcArr = array [0..255] of Word;
  TcrcArrDW = array [0..255] of LongWord;

const
  P_16: Word = $A001;
  P_CCITT: Word = $1021;
  P_DNP: Word = $A6BC;
  P_KERMIT: Word = $8408;
  P_SICK: Word = $8005;
  P_32: LongWord = $EDB88320;
var
  crc_tab16, crc_tabccitt, crc_tabdnp, crc_tabkermit: TcrcArr;
  crc_tab32: TcrcArrDW;

function Calcu_crc_16(const initialCRC: Word; const DataStr: string): Word;
var
  i: integer;
  tmp, short_c, crc: Word;
  aByte: Byte;
begin
  crc := initialCRC;
  for i := 1 to Length(DataStr) do
  begin
    aByte := ord(DataStr[i]);
    short_c := ($00ff and aByte);
    tmp := crc xor short_c;
    crc := (crc shr 8) xor crc_tab16[ tmp and $ff ];
  end;
  result := crc;
end;

function Calcu_crc_sick(const DataStr: string): Word;
var
  i: integer;
  short_c, short_p, crc, high_byte, low_byte: Word;
  aByte, prev_byte: Byte;
begin
  crc := $0000;
  prev_byte := 0;
  for i := 1 to Length(DataStr) do
  begin
    aByte := ord(DataStr[i]);
    short_c := ($00ff and aByte);
    short_p := ($00ff and prev_byte) shl 8;
    if (crc and $8000) = $8000 then crc := (crc shl 1) xor P_SICK
    else crc := (crc shl 1);
    crc := crc and $FFFF;
    crc := crc xor (short_c or short_p);
    prev_byte := aByte;
  end;
  low_byte := (crc and $ff00) shr 8;
  high_byte := (crc and $00ff) shl 8;
  result := low_byte or high_byte;
end;

function Calcu_crc_ccitt(const initialCRC: Word; const DataStr: string): Word;
var
  i: integer;
  tmp, short_c, crc: Word;
  aByte: Byte;
begin
  crc := initialCRC;
  for i := 1 to Length(DataStr) do
  begin
    aByte := ord(DataStr[i]);
    short_c := ($00ff and aByte);
    tmp := (crc shr 8) xor short_c;
    crc := (crc shl 8) xor crc_tabccitt[tmp];
  end;
  result := crc;
end;