德尔福XE3 - >整数的字节数组 [英] Delphi XE3 -> Integer to array of Bytes

查看:90
本文介绍了德尔福XE3 - >整数的字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据结构:

data = array of integer;

我从一个装满它。

I have filled it from an

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

处理这些块后,我不得不把他们带回到字节...

after processing these blocks i have to bring them back to "bytes"...

任何想法?

推荐答案

您可以在一个班轮使用移动做到这一点。

You can do this in a one-liner using Move.

Move(source[0], dest[0], Length(source)*SizeOf(source[0]));

如果您需要执行一个网络/主机字节顺序转换,那么你可以在整数数组后运行移动

If you need to perform a network/host byte order transformation, then you can run across the integer array after the Move.

在相反的方向,你做这一切反向。

In the opposite direction you do it all in reverse.

如果你没有字节序的问题,那么你可能实际上并不需要转换为字节数组的。这是可能的,你可以使用整数数组原样。请记住,没有字节顺序问题上,字节和整型数组的内存布局是相同的(这就是为什么你能够与块复制移动)。

If you haven't got byte order issues then you might not actually need to convert to a byte array at all. It's possible that you can use the integer array as is. Remember that, without byte order issues, the memory layout of the byte and integer arrays are the same (which is why you are able to blit with Move).

这篇关于德尔福XE3 - >整数的字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆