怎样将一个pByteArray类型的数组的每四位转化成为一位16进制数。并以字符串显示出来。紧急求助。天灵灵,地灵灵,各路神仙快显灵。各路打小虾米们快来帮忙啊。小弟该着急死啦。还有一个要求是速度要快。
解决方案 »
- delphi里面怎么截取字符串?
- 怎样获取PCI视频采集卡上的数据
- 打个源程序,报"could not create output file'..\obj\mesg_stru.dcu'"
- 如何合并2个内存流?
- 如何在主窗口的panel中显示另一窗口
- 上一个问题还没解决,所以只有找其它的办法。我要实现直接把邮件发到对方的SMTP服务器
- 我创建了一个COM,注册通过,VBS创建也没问题,但所有接口都找不到,请指点。(带源码)
- 如何获得一个互联网上文件的大小,如http://www.aaa.com/1.zip
- shellexcute怎么用阿?
- 如何实现代理服务器?
- 怎样才能使应用程序不被第二次打开
- 程序打包
//...
s :='';
for i:= 0 to length(arr)-1 do
s := s+ inttohex(arr[i],2);result := s;
我想找一个快一点的算法。
var
arr :pByteArray;
s :string;
i,v:integer;
begin
GetMem(arr,16);
for i:=0 to 15 do
arr[i]:=i;
s :='';
for i:= 0 to 3 do
begin
Move(arr[i*4],v,4);
s := s+' '+inttohex(v,4);
end;
ShowMessage(s);
FreeMem(arr);
end;
strTmp := ''; //最终的字符串结果
strLen := Length(array); //数组的总长度
while (index + 3)< strLen do //每次能连续取到四个数字则取数否则终止
{
iTmp := 0;
for j:= 0 to 3 do
iTmp := iTmp * 2 + array[index + j]; //计算每次取得的四个数合并后对应的数值
strTmp := strTmp + IntToHex(iTmp);
index := index + 4;
}
var
index, strLen, iTmp, j: Integer;
strTmp: string;
begin
Result := '';
index := 0; //指示从数组的第几个数字开始连续取四个(0或1的)数字
strTmp := ''; //最终的字符串结果
strLen := Length(ByteArray); //数组的总长度
while (index + 3)< strLen do //每次能连续取到四个数字则取数否则终止
begin
iTmp := 0;
for j:= 0 to 3 do
iTmp := iTmp * 2 + ByteArray[index + j]; //计算每次取得的四个数合并后对应的数值
strTmp := strTmp + IntToHex(iTmp, 2);
index := index + 4;
end;
Result := strTmp;
end;procedure TForm1.Button1Click(Sender: TObject);
const
ByteArray1: array[1..12] of Byte=(1,1,0,1, 1,0,1,1, 0,1,0,1);
begin
ShowMessage(GetString(ByteArray1));
end;