hexToFloat(hex)
Last updated June 22, 2010
Version: 1 | Requires: CF6 | Library: MathLib
Description:
Converts a 32-bit hexadecimal representation (IEEE 754 floating-point number) to a java Float
Return Values:
Returns a number.
Example:
<cfset floatValue = HexToFloat("C00FFEE") />
<cfoutput>floatValue = #floatValue#</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
hex | Hex input. | Yes |
Full UDF Source:
<!---
Converts a 32-bit hexadecimal floating-point number to a java float
@param hex Hex input. (Required)
@return Returns a number.
@author Leigh (cfsearching@yahoo.com)
@version 1, June 22, 2010
--->
<cffunction name="hexToFloat" returntype="numeric" access="public" output="false"
hint="Converts a 32-bit hexadecimal representation (IEEE 754 floating-point number) to a java Float">
<cfargument name="hex" type="string" required="true" />
<cfset var longValue = "">
<cfif reFindNoCase("[^[:xdigit:]]", arguments.hex)>
<cfthrow message="Argument.hex does not contain a recognized hexidecimal string" type="InvalidArgument" />
</cfif>
<cfset longValue = javacast("long", 0).parseLong( arguments.hex, 16 ) />
<cfreturn javacast("float", 0).intBitsToFloat( longValue.intValue() ) />
</cffunction>
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016