<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>TOBINARY</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">TOBINARY</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Calculates the binary representation of Base64-encoded data. 
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Returns</span>
<p>
The binary representation of Base64-encoded data.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Category</span>
<p>
Conversion functions, String functions
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Function syntax</span><pre>ToBinary(string_in_Base64 or binary_value)
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">See also</span><ul>

<li>BinaryDecode for conversion of binary-encoded data, including Base64, to binary data</li>

<li>cffile for information about loading and reading binary data</li>

<li>cfwddx for information about serializing and deserializing binary data</li>

<li>IsBinary and ToBase64 for checking format and converting to Base64 </li>

<li>Len for determining the length of a binary object</li>

<li>"Binary data type and binary encoding" in Chapter&#160;3, "Using ColdFusion Variables," in ColdFusion MX Developer's Guide</li>
</ul>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Parameters</span>
<p>

</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Usage</span>
<p>
Macromedia recommends that you use the BinaryDecode function to convert Base64 encoded data to binary data in all new applications.
</p>

<p>
If you pass a binary value to this function, it returns the input value.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Example</span><pre>&lt;h3&gt;ToBinary Example&lt;/h3&gt;
&lt;!---- Initialize data. ----&gt;
&lt;cfset charData = &quot;&quot;&gt;
&lt;!---- Create a string of ASCII characters (32-255); concatenate them. ----&gt;
&lt;cfloop index = &quot;data&quot; from = &quot;32&quot; to = &quot;255&quot;&gt;
   &lt;cfset ch = chr(data)&gt;
   &lt;cfset charData = charData &amp; ch&gt;
&lt;/cfloop&gt;
&lt;p&gt;The following string is the concatenation of all characters (32 to 255) 
from the ASCII table.&lt;br&gt;
&lt;cfoutput&gt;#charData#&lt;/cfoutput&gt;&lt;/p&gt;
&lt;!----- Create a Base64 representation of this string. -----&gt;
&lt;cfset data64 = toBase64(charData)&gt;

&lt;!--- Convert string to binary. ----&gt;
&lt;cfset binaryData = toBinary(data64)&gt;
&lt;!--- Convert binary back to Base64. ---&gt;
&lt;cfset another64 = toBase64(binaryData)&gt;
&lt;!---- Compare another64 with data64 to ensure that they are equal. ----&gt;
&lt;cfif another64 eq data64&gt;
   &lt;h3&gt;Base64 representation of binary data is identical to the Base64
representation of string data.&lt;/h3&gt;
&lt;cfelse&gt;
   &lt;h3&gt;Conversion error.&lt;/h3&gt;
&lt;/cfif&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="STRING_IN_BASE64">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">STRING_IN_BASE64</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>A string in Base64 format to convert to binary.</p>

  </td>
  </tr>
  </table>
</div>

  </body>
</html>
