SQLTeam.com | Weblogs | Forums

Convert a binary float to FLOAT datatype

Hi
I am hoping someone can help with a function that can convert a binary(24) data type to a Float or Real datatype? The DB is storing an array of three Float numbers in a binary format but the company does not disclose how to convert the binary datatype to the original Float data required.
An example of the data stored - 0xF82D0D2D481C5DC0931FF50A9E2A59C00000000000C05140
Any assistance is greatly appreciated.
Cheers

Probably this!?:

DECLARE @binary binary(24)
SET @binary = 0xF82D0D2D481C5DC0931FF50A9E2A59C00000000000C05140

SELECT
    CAST(CAST(SUBSTRING(@binary, 1, 8) AS bigint) AS float),
    CAST(CAST(SUBSTRING(@binary, 9, 8) AS bigint) AS float),
    CAST(CAST(SUBSTRING(@binary,17, 8) AS bigint) AS float)
1 Like

Thanks ScottPletcher for the reply.
I tried the code you suggested above with another example and it came out correct on the front end application the DB services.
The array actually represents the x, y, z co-ordinates of a point in a DICOM image.
For example the binary value 0xDDEEED97D20541C0127A806BBE3F32400000000000805340 represents -34.63, 17.655, -1183.5 on the image but the code produces
-2.45476351055094E+18, 1.33151784008307E+18, 8409920
Thanks again for replying and your help.
Cheers