谁来看看我这段C -> Delphi的代码对不对? 超短,不费眼!(100分)

B

bjaman

Unregistered / Unconfirmed
GUEST, unregistred user!
C代码:
String CompactCipherTime(TDateTime DT)
{
String Scipher;
char Buffer[16];
DWORD dw;
Word Year, Month, Day, Hour, Min, Sec, MSec;
DecodeDate(DT, Year, Month, Day);
DecodeTime(DT, Hour, Min, Sec, MSec);
dw=((Sec&amp;63)>>1)+((Min&amp;63)<<5)+((Hour&amp;31)<<11)+((Day&amp;31)<<16)+((Month&amp;15)<<21)+(((Year % 1000)&amp;127)<<25);
itoa(dw,Buffer,16);
for(int i=0;i<8;i++)
Buffer=UpCase(Buffer);
Scipher=Buffer;
return(Scipher);
}
翻译过来的Delphi代码:
function CompactCipherTime(aDateTime :TDateTime) : string;
var
dw : LongWord;
Year,Month,Day,Hour,Min,Sec,MSec : word;
Buffer : string;
begin
DecodeDate(aDateTime,Year,Month,Day);
DecodeTime(aDateTime,Hour,Min,Sec,MSec);
dw := ((Sec and 63) shr 1) + ((Min and 63) shl 5) + ((Hour and 31) shl 11) +
((Day and 31) shl 16) + ((Month and 15) shl 21) + (((Year mod 1000) and 127) shl 25);
Buffer := UpperCase(IntToStr(dw));
Buffer := Copy(Buffer,1,8);
Result := Buffer;
end;
 
这段代码是根据传入的一个日期型参数,经过计算,得到一个八位的十六进制字符串。
请看看我翻译的语法和语义上哪里不对?如果不对,哪里有问题,请指出来!谢谢!
 
最简单的测试方法就是, 看结果!
 
function CompactCipherTime(aDateTime :TDateTime) : string;
var
dw : LongWord;
Year,Month,Day,Hour,Min,Sec,MSec : word;
begin
DecodeDate(aDateTime,Year,Month,Day);
DecodeTime(aDateTime,Hour,Min,Sec,MSec);
dw := ((Sec and 63) shr 1) + ((Min and 63) shl 5) + ((Hour and 31) shl 11) +
((Day and 31) shl 16) + ((Month and 15) shl 21) + (((Year mod 1000) and 127) shl 25);
Result := IntToHex(dw, 0);
end;
 
to ErrorCode:
谢谢!果然是这我把itoa()理解错了!
 
接受答案了.
 
顶部