Ergänzend noch dazu zwei Methoden, um
Single- und
Double-Werte zu flippen:
Delphi-Quellcode:
type
BytePos = (EndVal, ByteVal);
PEndianCnvDblRec = ^EndianCnvDblRec;
PEndianCnvSnglRec = ^EndianCnvSnglRec;
EndianCnvDblRec = packed record
case pos: BytePos of
EndVal: (EndianVal: double);
ByteVal: (Bytes: array[0..SizeOf(Double)-1] of byte);
end;
EndianCnvSnglRec = packed record
case pos: BytePos of
EndVal: (EndianVal: Single);
ByteVal: (Bytes: array[0..SizeOf(Single)-1] of byte);
end;
procedure SwapBytesDouble( A, B: PEndianCnvDblRec );
var
i: integer;
begin
for i := high(A.Bytes) downto low(A.Bytes) do
A.Bytes[i] := B.Bytes[High(A.Bytes) - i];
end;
procedure SwapBytesSingle( A, B: PEndianCnvSnglRec );
var
i: integer;
begin
for i := high(A.Bytes) downto low(A.Bytes) do
A.Bytes[i] := B.Bytes[High(A.Bytes) - i];
end;
Quelle: http://edn.embarcadero.com/article/28964