-1
在Delphi中有沒有相當於bitconverter.getbytes?相當於delphi中的c#bitconverter
https://msdn.microsoft.com/en-us/library/fk3sts66(v=vs.110).aspx
在Delphi中有沒有相當於bitconverter.getbytes?相當於delphi中的c#bitconverter
https://msdn.microsoft.com/en-us/library/fk3sts66(v=vs.110).aspx
只需Move()
輸入變量入適當大小的一個字節數組,例如:
var
value: Smallint;
arr: array[0..SizeOf(Smallint)-1] of Byte;
begin
value := ...;
Move(value, arr[0], SizeOf(value));
end;
或者:
type
TBytes = array of Byte;
function GetBytes(value: Smallint): TBytes;
begin
SetLength(Result, SizeOf(value));
Move(value, Result[0], SizeOf(value));
end;
var
value: Smallint;
arr: TBytes;
begin
value := ...;
arr := GetBytes(value);
end;
可以使用一個簡單的轉換。使用相同類型的雷米,看起來像這樣:
var
value: Smallint;
arr: array[0..SizeOf(Smallint)-1] of Byte;
begin
value := ...;
// by value cast:
Smallint(arr) := value;
// or by address cast:
PSmallint(@arr)^ := value;
end;
或本:
var
value: Smallint;
arr: TBytes;
begin
value := ...;
SetLength(arr, SizeOf(value));
PSmallint(arr)^ := value;
end;