function TwoToFour(TwoNum:Byte):WORD; var a:Array[0..1] of Byte; w:^WORD; begin a[0]:=TwoNum; a[1]:=0; w:=@a[0]; w^:=w^ shl 4; a[0]:=a[0] shr 4; Result:=w^; end; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(IntToHex(TwoToFour($F1),4)); end;
楼主的意思是单字节转换为双字节吧? 假如是这样的: 请你先明确F1是字符串类型的吗? 假如是这样的: var S: String; TP1, TP2: Byte; begin S := 'F1'; TP1 := IntToStr('$' + S[1]); TP2 := IntToStr('$' + S[2]); S := IntToHex(TP1,2) + IntToHex(TP2,2); //S就是你要的结果了 end;
var
a:Array[0..1] of Byte;
w:^WORD;
begin
a[0]:=TwoNum;
a[1]:=0;
w:=@a[0];
w^:=w^ shl 4;
a[0]:=a[0] shr 4;
Result:=w^;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToHex(TwoToFour($F1),4));
end;
请你先明确F1是字符串类型的吗? 假如是这样的:
var S: String;
TP1, TP2: Byte;
begin
S := 'F1';
TP1 := IntToStr('$' + S[1]);
TP2 := IntToStr('$' + S[2]);
S := IntToHex(TP1,2) + IntToHex(TP2,2); //S就是你要的结果了
end;
function TwoToFour(TwoNum:Byte):WORD;
asm
mov ah,0
mov al,TwoNum
shl ax,4
shr al,4
end;
t:word;
begin
t:=$f1;
asm
mov ax,t;
shl ax,4;
shr al,4;
mov t,ax;
end;
SHOWMEssage(INTTOHEX(t,4));
end;