User Guide

886 Chapter 3: ColdFusion Functions
ToBinary
Description
Calculates the binary representation of Base64-encoded data.
Returns
The binary representation of Base64-encoded data.
Category
Conversion functions, String functions
Function syntax
ToBinary(string_in_Base64 or binary_value)
See also
BinaryDecode for conversion of binary-encoded data, including Base64, to binary data
cffile for information about loading and reading binary data
cfwddx for information about serializing and deserializing binary data
IsBinary and ToBase64 for checking format and converting to Base64
Len for determining the length of a binary object
“Binary data type and binary encoding” in Chapter 3, “Using ColdFusion Variables,” in
ColdFusion MX Developers Guide
Parameters
Usage
Macromedia recommends that you use the BinaryDecode function to convert Base64 encoded
data to binary data in all new applications.
If you pass a binary value to this function, it returns the input value.
Example
<h3>ToBinary Example</h3>
<!---- Initialize data. ---->
<cfset charData = "">
<!---- Create a string of ASCII characters (32-255); concatenate them. ---->
<cfloop index = "data" from = "32" to = "255">
<cfset ch = chr(data)>
<cfset charData = charData & ch>
</cfloop>
<p>The following string is the concatenation of all characters (32 to 255)
from the ASCII table.<br>
<cfoutput>#charData#</cfoutput></p>
<!----- Create a Base64 representation of this string. ----->
<cfset data64 = toBase64(charData)>
Parameter Description
string_in_Base64 A string in Base64 format to convert to binary.