C语言代码转成Pascal,谢谢。(100)

  • 主题发起人 主题发起人 silaszhe
  • 开始时间 开始时间
S

silaszhe

Unregistered / Unconfirmed
GUEST, unregistred user!
CRC校验WORD C_Protocol::calcCRC(char *pTempBuf, int usTempLength){ unsigned int reg16; unsigned char regHi, regLow; unsigned char charCheck, charOut; int i, j; reg16 = 0xFFFF; for (i=0; i<usTempLength; i++) { regHi = (reg16 >> 8) & 0x00FF; regLow = reg16 & 0x00FF; charCheck = pTempBuf; reg16 = regHi ^ charCheck; for (j=0; j<8; j++) { charOut = reg16 & 0x0001; reg16 = reg16 >> 1; if (0x0001 == charOut) { reg16 = reg16 ^ 0xA001; } } } return reg16;}
 
function C_Protocol.calcCRC(pTempBuf: Pchar; usTempLength: integer): word;var reg16: integer; regHi, regLow: char; charCheck, charOut: char; i, j: integer;begin reg16 := $FFFF; for i := 0 to usTempLength - 1 do begin regHi := char((reg16 shr 8) and $00FF); regLow := char(reg16 and $00FF); charCheck := pTempBuf; reg16 := ord(regHi) xor ord(charCheck); for j := 0 to 8 - 1 do begin charOut := char(reg16 and $0001); reg16 := reg16 shr 1; if char($0001) = charOut then begin reg16 := reg16 xor $A001; end; end; end; Result := reg16;end;
 
reg16 = regHi ^ charCheck;reg16 := ord(regHi) xor ord(charCheck);好!
 
后退
顶部