CFLib.org – Common Function Library Project

floatToHex(floatValue[, usePadding])

Last updated June 22, 2010

author

Leigh

Version: 0 | Requires: CF6 | Library: MathLib

Description:
Converts a java float to a 32-bit hexadecimal representation (IEEE 754 floating-point number)

Return Values:
Returns a string.

Example:

<cfset hexValue = FloatToHex( "9.937777E-32" ) />
<cfoutput>hexValue = #hexValue#</cfoutput>

Parameters:

Name Description Required
floatValue Numeric value. Yes
usePadding Boolean to determine if padding is used on the result. Defaults to true. No

Full UDF Source:

<!---
 Converts a java float to a 32-bit hexadecimal representation
 
 @param floatValue 	 Numeric value. (Required)
 @param usePadding 	 Boolean to determine if padding is used on the result. Defaults to true. (Optional)
 @return Returns a string. 
 @author Leigh (cfsearching@yahoo.com) 
 @version 0, June 22, 2010 
--->
<cffunction name="floatToHex" returntype="string" access="public" output="false"
        hint="Converts a java float value to a 32-bit hexadecimal representation (IEEE 754 floating-point number)">
    <cfargument name="floatValue" type="numeric" required="true" />
    <cfargument name="usePadding" type="boolean" default="true" />

    <cfset var floatRef = javacast("float", 0) />
    <cfset var intValue = floatRef.floatToIntBits( javacast("float", arguments.floatValue) ) />
    <cfset var result   = formatBaseN(intValue, 16) />

    <!--- pad hex value with leading zeroes --->
    <cfif arguments.usePadding>
        <cfset result =  right("00000000"& result, 8) />
    </cfif>
    
    <cfreturn result />
</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