怎么将两个Char型变量合并成一个SmallInt型变量
如何将两个Char型变量合并成一个SmallInt型变量
请问一下如何将两个Chart型变量的值分别赋给SmallInt型变量的高8位和低8位
------解决方案--------------------
var data : array[0..1] of char;
Result := (Byte(data[0]) shl 8) or Byte(data[1]);
------解决方案--------------------
procedure TForm1.FormCreate(Sender: TObject);
type
xxxx = record
x1: Byte;
x2: Byte;
end;
var
char1: array [0 .. 1] of Char;
char2: array [0 .. 1] of Char;
ooo: xxxx;
i: SmallInt;
begin
char1[0] := 'A';
char2[0] := 'B';
ooo.x1 :=byte(char1[0]);
ooo.x2 :=byte(char2[0]);
i := SmallInt(PSmallInt(@ooo)^);
ShowMessage(IntTohex(i,4));
end;
请问一下如何将两个Chart型变量的值分别赋给SmallInt型变量的高8位和低8位
------解决方案--------------------
var data : array[0..1] of char;
Result := (Byte(data[0]) shl 8) or Byte(data[1]);
------解决方案--------------------
procedure TForm1.FormCreate(Sender: TObject);
type
xxxx = record
x1: Byte;
x2: Byte;
end;
var
char1: array [0 .. 1] of Char;
char2: array [0 .. 1] of Char;
ooo: xxxx;
i: SmallInt;
begin
char1[0] := 'A';
char2[0] := 'B';
ooo.x1 :=byte(char1[0]);
ooo.x2 :=byte(char2[0]);
i := SmallInt(PSmallInt(@ooo)^);
ShowMessage(IntTohex(i,4));
end;