Converting numbers between base 10 and base 16 using ColdFusion

Readability

Converting numbers between base 10 and base 16 using ColdFusion

The fol­low­ing exam­ple shows how you can con­vert num­bers and strings between base 10 (dec­i­mal) and base 16 (hexa­dec­i­mal) in Cold­Fu­sion using the formatBaseN() and inputBaseN() functions.


formatBaseN(255, 16): #formatBaseN(255, 16)#
formatBaseN(6724044, 16): #formatBaseN(6724044, 16)#
inputBaseN("FF", 16): #inputBaseN("FF", 16)#
inputBaseN("6699CC", 16): #inputBaseN("6699CC", 16)#

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

formatBaseN(255, 16): ff
formatBaseN(6724044, 16): 6699cc
inputBaseN(“FF”, 16): 255
inputBaseN(“6699CC”, 16): 6724044

The following example shows how you can convert numbers and strings between base 10 (decimal) and base 16 (hexadecimal) in ColdFusion using the formatBaseN() and inputBaseN() functions.

<cfoutput>
<table border="1">
<tr>
    <td>formatBaseN(255, 16):</td>
    <td>#formatBaseN(255, 16)#</td> <!-- ff -->
</tr>
<tr>
    <td>formatBaseN(6724044, 16):</td>
    <td>#formatBaseN(6724044, 16)#</td> <!-- 6699cc -->
</tr>
<tr>
    <td>inputBaseN("FF", 16):</td>
    <td>#inputBaseN("FF", 16)#</td> <!-- 255 -->
</tr>
<tr>
    <td>inputBaseN("6699CC", 16):</td>
    <td>#inputBaseN("6699CC", 16)#</td> <!-- 6724044 -->
</tr>
</table>
</cfoutput>

The previous example outputs the following text:

formatBaseN(255, 16): ff
formatBaseN(6724044, 16): 6699cc
inputBaseN(“FF”, 16): 255
inputBaseN(“6699CC”, 16): 6724044

Leave a Reply