字节的合并

2020-01-07 08:30:53来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

字节的合并

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.

原文链接:https://www.cnblogs.com/tobetterlife/p/12161550.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:一秒可生成500万ID的分布式自增ID算法—雪花算法 (Snowflake,De

下一篇:深入delphi编程理解之消息(一)WINDOWS原生窗口编写及消息处理