Converting Hex To Float Sql
I am trying to find a way of converting HEX to a float in SQL Server. An example value is 0x42c80000 which corresponds to 100.00. It is easy to convert this Hex value to an Int usi
Solution 1:
DECLARE@BinaryFloatASVARBINARY(4);
SET@BinaryFloat=CONVERT(VARBINARY, '0x42c80000',1);
SELECT SIGN(CAST(@BinaryFloatASINT))
* (1.0+ (CAST(@BinaryFloatASINT) &0x007FFFFF) *POWER(CAST(2ASREAL), -23))
*POWER(CAST(2ASREAL), (CAST(@BinaryFloatASINT) &0x7f800000) /0x00800000-127)
Wish I could claim credit, but alas: http://multikoder.blogspot.com.au/2013/03/converting-varbinary-to-float-in-t-sql.html
Also, interesting blog https://blogs.msdn.microsoft.com/psssql/2010/11/01/how-it-works-sql-parsing-of-numbers-numeric-and-float-conversions/
Post a Comment for "Converting Hex To Float Sql"