这段c代码转换为delphi(50分)

  • 主题发起人 主题发起人 liuying1129
  • 开始时间 开始时间
L

liuying1129

Unregistered / Unconfirmed
GUEST, unregistred user!
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&63)>>1)+((Min&63)<<5)+((Hour&31)<<11)+((Day&31)<<16)+((Month&15)<<21)+(((Year % 1000)&127)<<25);
itoa(dw,Buffer,16);
for(int i=0;i<8;i++)
Buffer=UpCase(Buffer);
Scipher=Buffer;
return(Scipher);
}
 
function CompactCipherTime(DT:TDateTime):string;
var Scipher:String;
Buffer:array[0..15] of char;
dw:DWORD;
Year, Month, Day, Hour, Min, Sec, MSec:Word;
i:Integer;
begin
DecodeDate(DT, Year, Month, Day);
DecodeTime(DT, 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:=uppercase(inttostr(dw));}
strpcopy(buffer,inttostr(dw));
for i:=0 to 7 do Buffer:=UpCase(Buffer);
Scipher:=Buffer;
result:=Scipher;
end;
 
TYZhang:
1、itoa(dw,Buffer,16);//这句好像没转换
 
buffer := format('%x', dw);
 
to liuying1129:
inttostr(dw)就是itoa(dw,Buffer,16);的转换.
 
多人接受答案了。
 
后退
顶部