The following piece of VBA is an Microsoft Excel worksheet function that converts a 32 bit hex string into its decimal equivalent as an ieee 754 floating point (real) number - it returns a double.
This only works if the hexadecimal number is all in lower case and is exactly 8 characters (4 bytes) long. It could be extended easily to be a bit smarter, and even to do double precision numbers (64 bits) - but this works for me for what I wanted, and I couldn't find it on the net anywhere else!
Function HEX2DECFL(strHexVal As String) As
Double ' ' Function to convert 4 byte (32 bit) Hex value ' to a floating point decimal number ' using IEE 754 ' ' Dave Stow ' ' Lookup array of hex digits to binary
digits ' String to put the full binary string into ' Each part of the floating point number Dim strExponentPart As String ' The
bits making up the exponent Dim strFraction As String ' The
string that makes up the fractional part of the mantissa Dim i As Integer ' Initialise the lookup tables for making
the binary string ' Generate binary string from hex ' Extract components of floating point
number based on: ' ----------------------------------- ' ----------------------------------- ' Correct for bias of 127 ' ----------------------------------- ' We've got all the bits - put it all
together End Function |