Delphi XE3 -> Integer to array of Bytes

后端 未结 5 1306
野趣味
野趣味 2021-01-02 22:52

I have a data structure:

data = array of integer;

I have filled it from an

source = array of byte;

with

5条回答
  •  孤街浪徒
    2021-01-02 23:26

    You mean like this?

    var
      i: integer;
      b1, b2, b3, b4: byte;
    begin
      b1 := byte(i);
      b2 := byte(i shr 8);
      b3 := byte(i shr 16);
      b4 := byte(i shr 24);
    

    Try, for instance,

    procedure TForm1.FormCreate(Sender: TObject);
    var
      i: integer;
      b1, b2, b3, b4: byte;
    begin
      i := $AABBCCDD;
      b1 := byte(i);
      b2 := byte(i shr 8);
      b3 := byte(i shr 16);
      b4 := byte(i shr 24);
      ShowMessage(IntToHex(b1, 2));
      ShowMessage(IntToHex(b2, 2));
      ShowMessage(IntToHex(b3, 2));
      ShowMessage(IntToHex(b4, 2));
    end;
    

提交回复
热议问题