User Guide

ToBinary 723
ToBinary
Description
Calculates the binary representation of Base64-encoded data.
Returns
The binary representation of Base64-encoded data.
Category
Conversion functions, Other functions, String functions
Function syntax
ToBinary(string_in_Base64 or binary_value)
See also
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
Parameters
Usage
Base64 provides 6-bit encoding of 8-bit ASCII characters. From Base64 data, you can recreate the
binary object that it represents, such as a GIF, JPG, or executable file.
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)>
<!--- Convert string to binary. ---->
<cfset binaryData = toBinary(data64)>
<!--- Convert binary back to Base64. --->
<cfset another64 = toBase64(binaryData)>
<!---- Compare another64 with data64 to ensure that they are equal. ---->
<cfif another64 eq data64>
<h3>Base64 representation of binary data is identical to the Base64
representation of string data.</h3>
Parameter Description
string_in_Base64 or
binary_value
A string or a variable that contains one:
In Base64 format to convert to binary
In binary format to test whether it is valid