Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.65 KB | None | 0 0
  1. function crc16(s:string):Word;
  2. var i,j:byte;
  3. begin
  4.   Result:=0;
  5.   for i:=1 to Length(s)do
  6.   begin
  7.       Result := Result xor Ord(s[i]) shl 8;
  8.       j := 8;
  9.       while j<>0 do
  10.       begin
  11.         if (Result and $8000 = $8000) then //( BYTE1(v2) & 0x80 )
  12.           Result := 2 * Result xor $8005
  13.         else
  14.           Result := Result * 2;
  15.         Dec(j);
  16.       end;
  17. end;
  18. end;
  19.  
  20. ////////////////////////////////////
  21. ///////////////////////////////////
  22. //...
  23.   tmp:=(len+lenID) div 2;
  24.   p1:=format('%0.4x',[crc16(Copy(szName+szID,1, tmp))]);
  25.   p2:=format('%0.4x',[crc16(Copy(szName+szID,tmp+1, len+lenID-tmp))]);
  26.   serial:='HT-'+p1+'-'+p2;
  27. //...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement