gpt4 book ai didi

arrays - Delphi XE3 -> 整数到字节数组

转载 作者:行者123 更新时间:2023-12-03 14:55:42 26 4
gpt4 key购买 nike

我有一个数据结构:

data = array of integer;

我已经从一个中填写了它

source = array of byte;

data[x] := Source[offset] or (Source[offset + 1] shl 8) or
(Source[offset + 2] shl 16) or (Source[offset + 3] shl 24);

处理完这些 block 后,我必须将它们恢复为“字节”...

有什么想法吗?

最佳答案

你的意思是这样吗?

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);

例如,尝试

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;

关于arrays - Delphi XE3 -> 整数到字节数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13634240/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com