字节的合并
程序员文章站
2022-03-03 08:19:23
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, V ......
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.