CFLib.org – Common Function Library Project

hexToFloat(hex)

Last updated June 22, 2010

author

Leigh

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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson