字节的合并

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    btn1: TButton;
    btn2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type
  T4ByteRec = packed record
    case Integer of
    0:
    (
     B1,B2,B3,B4: Byte ;
    );
    1:
    (
     BS:array [0..3] of Byte ;
    );
    2:
    (
      //x64:Int64;  //x64 是8位
      x64:integer;
    );
  end;

procedure TForm1.btn1Click(Sender: TObject);
var
  ARec: T4ByteRec ;
  t:array[0..3] of byte;
  pint:PInteger;
begin
  ARec.B1 :=$1;
  ARec.B2:=$2;
  ARec.B3 :=$3 ;
  AReC.B4 :=$4;

  ShowMessage( IntToHex(integer(ARec.x64),4)) ;
end ;


procedure TForm1.btn2Click(Sender: TObject);
var
  n1,n2: Cardinal;
  num64: Int64;
  rec: Int64Rec;
begin

  n1 := $44332211;
  n2 := $AABBCCDD;
  rec.Lo := n1;
  rec.Hi := n2;
  num64 := Int64(rec);
  ShowMessage(IntToHex(num64, 0)); //AABBCCDD44332211
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  p1:pshortint;
  p2:psmallint;

  b1:array[0..0] of Byte;
  b2:array[0..1] of Byte;
begin
  IntToHex(-1,4);
  StrToInt('$FFFF');

  b1[0]:= $FF;

  b2[0]:= $FF;
  b2[1]:=$FF;

  p1:=@b1[0];
  p2:=@b2[0];

  //ShowMessage(IntToStr(p1^));
 // ShowMessage(IntToStr(p2^));
end;

end.
posted @ 2020-01-07 14:55  创新创造学习整合套路  阅读(...)  评论(...编辑  收藏