我有一种 ST 代码中的 Action 监听器(类似于 Pascal),它返回一个整数。然后我有一个 CANopen 函数,它允许我仅以字节数组形式发送数据。我如何从这些类型进行转换?
感谢您的回答。
最佳答案
您可以使用Move
标准函数将整数 block 复制到四个字节的数组中:
var
MyInteger: Integer;
MyArray: array [0..3] of Byte;
begin
// Move the integer into the array
Move(MyInteger, MyArray, 4);
// This may be subject to endianness, use SwapEndian (and related) as needed
// To get the integer back from the array
Move(MyArray, MyInteger, 4);
end;
PS:我已经几个月没有用 Pascal 编写代码了,所以可能会有错误,请随时修复。
关于pascal - 如何将整数转换为字节数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15038838/