function ConvertToSingle(Data: array[0..3] of byte): Single;
var
ASingle: Single absolute Data;
begin
Result := ASingle;
end;
Hmmm ... old school solution?With the exception of possible endianness mismatch (which can be easily solved by applying System.BEToN or System.LEToN to another absolut alias of type LongWord/LongInt), this is the best solution IMO.Code: [Select]function ConvertToSingle(Data: array[0..3] of byte): Single;
var
ASingle: Single absolute Data;
begin
Result := ASingle;
end;
But I'm sure there are easier and more secure ways.
If the buffer is declared as of type single array, you can simply read it directly. Mind you: byte order can play dirty tricks here.I doubt that `cardinal.tosingle` is what is wanted. IMO `cardinal.tosingle` simply converts the integer value to a single and does not map the floating point structure. Here the values from the OP
But anyway a cardinal or a longword can be converted like this:
uses sysutils; var buffer:array[0..bufsize_in_4byte_steps-1] of cardinal; s:single; begin s := Buffer[0].ToSingle; //first element... etc.
It does not matter if you use absolute or not. You should be aware of endianness.
You can use SwapEndian:
if EndianSwap then
You can use SwapEndian.
if EndianSwap then
LOL, no not the name.You can use SwapEndian.
if EndianSwap then
It's just a parameter name; it may as well be called DoTheSwapDance for all it matters :D