谁帮我把这段代码翻译为delphi,200分相送,谢谢 ( 积分: 200 )

  • 主题发起人 主题发起人 yyw7467
  • 开始时间 开始时间
Y

yyw7467

Unregistered / Unconfirmed
GUEST, unregistred user!
Dim Buf() As Byte, TempBuf() As Integer, TempBuf2() As Integer

ReDim Buf(99999) As Byte

BufLength =10000
If BufLength < 100000 Then ReDim Preserve Buf(BufLength - 1) As Byte

ReDim TempBuf(BufLength / 2 - 1) As Integer, TempBuf2(BufLength / 4 - 1) As Integer
Call RtlMoveMemory(TempBuf(0), Buf(0), BufLength)

For i = 0 To BufLength / 4 - 1
TempBuf2(i) = Int(CLng(TempBuf(i * 2)) + CLng(TempBuf(i * 2 + 1))) / 2
Next i

BufLength = BufLength / 2
ReDim Buf(BufLength - 1)
Call RtlMoveMemory(Buf(0), TempBuf2(0), BufLength)

ReDim TempBuf(BufLength / 2 - 1) As Integer
Call RtlMoveMemory(TempBuf(0), Buf(0), BufLength)
ReDim Buf(BufLength / 2 - 1) As Byte
For i = 0 To BufLength / 2 - 1
Buf(i) = Int(TempBuf(i) / 256 + 128)
Next i
BufLength = BufLength / 2
 
Dim Buf() As Byte, TempBuf() As Integer, TempBuf2() As Integer

ReDim Buf(99999) As Byte

BufLength =10000
If BufLength < 100000 Then ReDim Preserve Buf(BufLength - 1) As Byte

ReDim TempBuf(BufLength / 2 - 1) As Integer, TempBuf2(BufLength / 4 - 1) As Integer
Call RtlMoveMemory(TempBuf(0), Buf(0), BufLength)

For i = 0 To BufLength / 4 - 1
TempBuf2(i) = Int(CLng(TempBuf(i * 2)) + CLng(TempBuf(i * 2 + 1))) / 2
Next i

BufLength = BufLength / 2
ReDim Buf(BufLength - 1)
Call RtlMoveMemory(Buf(0), TempBuf2(0), BufLength)

ReDim TempBuf(BufLength / 2 - 1) As Integer
Call RtlMoveMemory(TempBuf(0), Buf(0), BufLength)
ReDim Buf(BufLength / 2 - 1) As Byte
For i = 0 To BufLength / 2 - 1
Buf(i) = Int(TempBuf(i) / 256 + 128)
Next i
BufLength = BufLength / 2
 
应该不难吧,大家帮个忙嘛
 
看得懂,不过不会Delphi;

拷来拷去的,是什么啊,加密解密?
 
var
buf: array of byte;
tempbuf: array of integer;
tempbuf2: array of integer;
buflength: integer;
i: integer;
begin
buflength := 10000;
setlength(buf,buflength);
setlength(tempbuf,buflength div 2);
setlength(tempbuf2,buflength div 4);


for i := low(tempbuf2) to high(tempbuf2) do begin
a := buf[i * 4] + buf[i*4 +1]*256;
b:= buf[i * 4 + 2] + buf[i*4 +3]*256;
tempbuf2 := round((a+b)* 0.5)
end;
此问题需知道byte/word/integer的字长和存储方式,一般是低字节在前,只要明白这个道理程序就非常简单了,实际上根本不用这么复杂,定义一个指向int的指针,就很容易完成这个数组的转换了。另外可以使用slice函数将静态(动态)数组截断
 
谢谢,测试一下,通过即给分
 
vavnine
看了一下,好像没翻译完哦,劳烦,劳烦
 
楼主不厚道!不给分!!
 
var
Buf:array of Byte;
TempBuf:array of Integer;
TempBuf2:array of integer;
BufLength:Integer;
begin
setlength(buf,99999);
BufLength:=10000;
If BufLength < 100000 Then
SetLength(Buf,BufLength - 1);
SetLength(TempBuf, BufLength div 2 -1);
SetLength(TempBuf2, BufLength div 4 -1);
RtlMoveMemory(TempBuf[0], Buf[0], BufLength);//这是什么procedure????
for i:=0 to high(TempBuf) do
begin
TempBuf2:=tempbuf[i*2]+TempBuf(i*2+1)div 2
end;

BufLength:=Buflength div 2;
Setlength(buflength-1);
RtlMoveMemory(Buf[0],TempBuf2[0],Buflength);
setlength(tempbuf,buflength div 2 -1);
RtlMoveMemory(Buf[0],TempBuf2[0],Buflength);
setlength(buf,buflength div 2 -1);
for i:=0 to high(Buf) do
Buf:=TempBuf div 256 +128;
BufLength:=BufLength div 2;
end;
end;
 
//这下应该没问题了
type
TRtlMoveMemory = function (Char1:variant
Source:Longint;Size:Longint):Longint;stdcall;
var
RtlMoveMemory:TRtlMoveMemory;
WH:HWnd;
Buf:array of Byte;
TempBuf:array of Integer;
TempBuf2:array of integer;
BufLength:Integer;
i:integer;
begin
WH:=LoadLibrary(PChar('kernel32.dll'));
RtlMoveMemory:=GetProcAddress(WH, PChar('RtlMoveMemory'));
setlength(buf,99999);
BufLength:=10000;
If BufLength < 100000 Then
SetLength(Buf,BufLength - 1);
SetLength(TempBuf, BufLength div 2 -1);
SetLength(TempBuf2, BufLength div 4 -1);
RtlMoveMemory(TempBuf[0], Buf[0], BufLength);
for i:=0 to high(TempBuf) do
begin
TempBuf2:=tempbuf[i*2]+TempBuf[i*2+1]div 2
end;

BufLength:=Buflength div 2;
Setlength(buf,buflength-1);
RtlMoveMemory(Buf[0],TempBuf2[0],Buflength);
setlength(tempbuf,buflength div 2 -1);
RtlMoveMemory(Buf[0],TempBuf2[0],Buflength);
setlength(buf,buflength div 2 -1);
for i:=0 to high(Buf) do
Buf:=TempBuf div 256 +128;
BufLength:=BufLength div 2;
end;
 
楼主??!!!!!
 
不是很满意,还是把贴结了,谢谢大家帮忙
 
后退
顶部