<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>BINARYDECODE</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">BINARYDECODE</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>
Converts a string to a binary object. Used to convert binary data that has been encoded into string format back into binary 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>
A binary object.
</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>BinaryDecode(string, binaryencoding)
</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>
<p>
BinaryEncode, CharsetEncode, CharsetDecode
</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">History</span>
<p>
ColdFusion&#160;MX&#160;7: Added this function.
</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">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>
Use this function to convert a binary-encoded string representation of binary data back to a binary object for use in your application. Binary data is often encoded as a string for transmission over many Internet protocols, such as HTTP and SMTP, or for storage in a database.
</p>

<p>
Macromedia recommends that you use the BinaryDecode function, not the ToBinary(base64data) function, to convert Base64-encoded data to binary data in all new applications.
</p>

<p>
See the following pages for additional information on handling binary data:
</p>
<ul>

<li>cffile for loading and reading binary data in files</li>

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

<li>IsBinary for checking variables for binary format</li>

<li>Len for determining the length of a binary object</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">Example</span>
<p>
The following example reads a GIF file as binary data, converts it to a binary-encoded string, converts the binary-encoded data back to binary data and writes the result to a file. It displays the encoded string and the image in the output file.
</p>
<pre>&lt;h3&gt;Binary Encoding Conversion Example&lt;/h3&gt;

&lt;!--- Do the following if the form has been submitted. ---&gt;
&lt;cfif IsDefined(&quot;Form.binEncoding&quot;)&gt;

   &lt;!--- Read in a binary data file. ---&gt;
   &lt;cffile action=&quot;readbinary&quot; 
file=&quot;C:\CFusionMX7\wwwroot\CFIDE\administrator\images\help.gif&quot; 
variable=&quot;binimage&quot;&gt;

   &lt;!--- Convert the read data to binary encoding and back to binary data. ---&gt;
   &lt;cfscript&gt;
      binencode=BinaryEncode(binimage, Form.binEncoding);
      bindecode=BinaryDecode(binencode, Form.binEncoding);
   &lt;/cfscript&gt;

   &lt;!---  Write the converted results to a file. ---&gt;
   &lt;cffile action=&quot;write&quot; file=&quot;C:\temp\help.gif&quot; output=&quot;#bindecode#&quot; 
addnewline=&quot;No&quot; &gt;

   &lt;!--- Display the results. ---&gt;
   &lt;cfoutput&gt;
      &lt;p&gt;&lt;b&gt;The binary encoding:&lt;/b&gt; #Form.binEncoding#&lt;/p&gt;
      
      &lt;p&gt;&lt;b&gt;The image converted into a binary-encoded string by BinaryEncode
         &lt;/b&gt;&lt;br&gt;
         #binencode#&lt;/p&gt;
      &lt;p&gt;&lt;b&gt;The image as written back to a file after converting back to binary
         using BinaryDecode&lt;/b&gt;&lt;br&gt;
      &lt;img src=&quot;C:\temp\help.gif&quot;&gt;&lt;br&gt; 
   &lt;/cfoutput&gt;
&lt;/cfif&gt;

&lt;!--- The input form. ---&gt;
&lt;form action=&quot;#CGI.SCRIPT_NAME#&quot; method=&quot;post&quot;&gt;
   &lt;b&gt;Select binary encoding&lt;/b&gt;&lt;br&gt;
   &lt;select size=&quot;1&quot; name=&quot;binEncoding&quot; &gt;
      &lt;option selected&gt;UU&lt;/option&gt;
      &lt;option&gt;Base64&lt;/option&gt;
      &lt;option&gt;Hex&lt;/option&gt;
   &lt;/select&gt;&lt;br&gt;
   &lt;br&gt;
   &lt;input type = &quot;Submit&quot; value = &quot;convert my data&quot;&gt;
&lt;/form&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="STRING">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">STRING</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 containing encoded binary data.</p>

  </td>
  </tr>
  </table>
</div>
<div id="BINARYENCODING">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">BINARYENCODING</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 specifying the algorithm used to encode the original binary data into a string; must be one of the following:</p><ul>

<li>Hex: the characters 0-9 and A-F represent the hexadecimal value of each byte; for example, 3A.</li>

<li>UU: data is encoded using the UNIX UUencode algorithm.</li>

<li>Base64: data is encoded using the Base64 algorithm, as specified by IETF RFC 2045, at www.ietf.org/rfc/rfc2045.txt</a>.</li>
</ul>


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

  </body>
</html>
