Delphi XE3 -> Integer to array of Bytes

后端 未结 5 1307
野趣味
野趣味 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:30

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

提交回复
热议问题