ToBinary

Description

Returns the binary representation of Base64 encoded data.

Category

Conversion functions

Syntax

ToBinary(string_in_Base64 or binary_value) 

See also

See:

Parameters

Parameter
Description
string_in_Base64 or binary_value
String in Base64 to convert to binary or binary value to test to ensure that it is an acceptable binary value.

Usage

Base64 provides 6 bit encoding of 8-bit ASCII characters. If you receive data in Base64, you can re-create the actual binary object that it represents, such as a .gif, .jpeg, or executable file, with the ToBinary function.

Example

<!--- This example shows the use of ToBinary and ToBase64 --->
<html>
<head>
<title>
ToBinary Example
</title>
</head>

<BASEFONT FACE = "Arial, Helvetica" SIZE = 2>
<body bgcolor = "#FFFFD5">

<H3>ToBinary Example</H3>

<!--------------------------------------------------------------------
Initialize data.
---------------------------------------------------------------------->
<cfset charData = "">
<!--------------------------------------------------------------------
Create a string of all ASCII characters (32-255) and 
concatenate them together.
---------------------------------------------------------------------->
<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>
<cfelse>
  <H3>Conversion error.</H3>
</cfif>
</body>
</html>