|
Here is a very simple conversion from a dynamic
byte array to a Single:
function BytesToSingle(Data:
TByteDynArray;
Position: Integer): Single; {------------------------------------------------------------------------- DESCRIPTION: Accepts a byte array and returns a Single. PARAMETERS: The byte array and an integer specifying the position in the array to start. RETURNS: Single -------------------------------------------------------------------------} const DATA_SIZE: Longint = 4; begin if Position <= High(Data) - (DATA_SIZE - 1) then Move(Data[Position], result, DATA_SIZE); end; And a routine to convert from a Single to
Bytes:
function SingleToBytes(Data: Single):
TByteDynArray;
{--------------------------------------------------------------------------- DESCRIPTION: Converts the Single to a 4byte array. PARAMETERS: Data The Single to convert RETURNS: TByteDynArray The byte values separated into a byte array ---------------------------------------------------------------------------} const DATA_SIZE : LongInt = 4; begin SetLength(result, DATA_SIZE); Move(Data, result[0], DATA_SIZE); end; The above routine could also easily be adapted to
work with an existing byte array and take a pPosition parameter like the
first routine.
|
_______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
