各位大虾,有一个C函数,能不能帮帮小弟将其转成Delphi,先谢了 (200分)

L

lsha

Unregistered / Unconfirmed
GUEST, unregistred user!
请各位大虾指教
 
<<左移
>>右移
&amp;与
这个函数就是把zb中的字符串转换后右传出去.
 
在delphi中左、右移shl , shr
 
是啊,但是在Delphi中pchar类型的变量好像不能用p1[0],p1[1],p1[2],p1[3]来表示啊,
请各位高手继续关注!!
 
procedure TForm3.Button1Click(Sender: TObject);
var
a:Longint;
p1:pchar;
x:Longint;
z:pchar;
begin
z:='333';
p1:=@a;
x:=(((ord(z[0])-48) shl 2) and $0fc) or (((ord(z[1])-48) shr 4) and $03) ;
p1[0]:=chr(x);
showmessage(inttostr(x));
showmessage(inttostr(a));
end;

我写了一部分。。试试。。我测试了。。。
 
其实PChar可以这样:
(p1)^
(p1+1)^
(p1+2)^
(p1+3)^
明白了?
 
p1[0],p1[1],p1[2],p1[3]也可以呀,我试了。
 
to youou:真是太感谢你了,实在是太感谢你了,你帮我解决了两个问题!!!
 
function c2i(zb:pchar ):integer;
var
a:integer;
p1:pchar;
begin
p1:= @char(a) ;
(p1+3)^:=char(((integer(zb^)shl 2)and $fc)or((integer((zb+1)^)shr 4)and $03));
(p1+2)^:= char(((integer((zb+1)^)shl 4)and $f0)or((integer((zb+2)^)shr 2)and $0f));
(p1+1)^:=char( ((integer((zb+2)^)shl 6)and $c0)or(integer((zb+3)^)and $3f) );
p1^:=char(((integer((zb+4)^)shl 2)and $fc)or((integer((zb+10)^)shr 2)and $03) );
result:=a ;
end;
 

Similar threads

S
回复
0
查看
987
SUNSTONE的Delphi笔记
S
S
回复
0
查看
805
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部