procedure TForm1.Button1Click(Sender: TObject); var s,s1:string; al:array[1..8] of byte; i:integer; begin //s1:=memo1.Lines.Text; s1:='1234567890abcdef'; setlength(s,2); for i:=1 to 8 do begin s:=copy(s1,(2*i-1),2); if byte(s[1])>=97 then al[i]:=(byte(s[1])-87)*16 else if byte(s[1])>=65 then al[i]:=(byte(s[1])-55)*16 else al[i]:=(byte(s[1])-48)*16; if byte(s[2])>=97 then al[i]:=al[i]+(byte(s[1])-87) else if byte(s[2])>=65 then al[i]:=al[i]+(byte(s[1])-55) else al[i]:=al[i]+(byte(s[2])-48); end; end;存在al中的是18,52,86,120,144,170,204,238也就是十六进的12h,34h,56h,78h,90h,abh,cdh,efh
Charles Calvert的《Delphi 2 程序设计大全》里有例子,不过挺复杂的,编了一个函数把字符转入16进制,和楼上的代码神似,好像更完善一些。可以一看。
例子:
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
i := StrToInt(copy(Trim(Edit1.text),1,2));
label1.Caption := IntToHex(i,1);
end;
现在之不过是把55换为屹屹变量而已,就不行了。无奈呀。
S是string怎么可以用byte!!当然错不用byte用strtoint就可以了
例如:现在就是在memo框中输入'1234567890abcdef',
第一次取出12作为a1[1],第二次取出34作为a1[2],第三次取出56作为a1[3]......
依次类推.注意数组a1为byte类型.
怎么实现呢?
谢谢!!
var
s,s1:string;
al:array[1..8] of byte;
i:integer;
begin
//s1:=memo1.Lines.Text;
s1:='1234567890abcdef';
setlength(s,2);
for i:=1 to 8 do
begin
s:=copy(s1,(2*i-1),2);
if byte(s[1])>=97 then al[i]:=(byte(s[1])-87)*16
else if byte(s[1])>=65 then al[i]:=(byte(s[1])-55)*16
else al[i]:=(byte(s[1])-48)*16;
if byte(s[2])>=97 then al[i]:=al[i]+(byte(s[1])-87)
else if byte(s[2])>=65 then al[i]:=al[i]+(byte(s[1])-55)
else al[i]:=al[i]+(byte(s[2])-48);
end;
end;存在al中的是18,52,86,120,144,170,204,238也就是十六进的12h,34h,56h,78h,90h,abh,cdh,efh