<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Convert Binary to Base64 String</title>
	<atom:link href="http://www.csharp411.com/convert-binary-to-base64-string/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.csharp411.com/convert-binary-to-base64-string/</link>
	<description>C# Information, Code, Tips and News</description>
	<lastBuildDate>Tue, 07 Sep 2010 15:50:57 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Grant</title>
		<link>http://www.csharp411.com/convert-binary-to-base64-string/comment-page-1/#comment-5510</link>
		<dc:creator>Grant</dc:creator>
		<pubDate>Sat, 05 Jun 2010 22:39:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/convert-binary-to-base64-string/#comment-5510</guid>
		<description>John&#039;s method will be faster and let someone define arbitrary mappings.  Unfortunately, you can&#039;t beat .NET&#039;s implementation since its written in C++ and is unsafe code.  You can use .NET Reflector to look at the Convert.ToBase64String method yourself.  Microsoft can get away with that because .NET assemblies are fully trusted.  When you think about it, C++ has some great and totally unsafe ways of doing this conversion.

On the whole though, unless you are converting huge amounts of these things (maybe to mime encode a big binary) you don&#039;t need a lot of speed.  

Thanks for this code, it gives me a head start on my own implementation.</description>
		<content:encoded><![CDATA[<p>John's method will be faster and let someone define arbitrary mappings.  Unfortunately, you can't beat .NET's implementation since its written in C++ and is unsafe code.  You can use .NET Reflector to look at the Convert.ToBase64String method yourself.  Microsoft can get away with that because .NET assemblies are fully trusted.  When you think about it, C++ has some great and totally unsafe ways of doing this conversion.</p>
<p>On the whole though, unless you are converting huge amounts of these things (maybe to mime encode a big binary) you don't need a lot of speed.  </p>
<p>Thanks for this code, it gives me a head start on my own implementation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Catfish</title>
		<link>http://www.csharp411.com/convert-binary-to-base64-string/comment-page-1/#comment-5486</link>
		<dc:creator>John Catfish</dc:creator>
		<pubDate>Thu, 13 May 2010 15:56:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/convert-binary-to-base64-string/#comment-5486</guid>
		<description>I almost forgot, It could also fit into the system cache!</description>
		<content:encoded><![CDATA[<p>I almost forgot, It could also fit into the system cache!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Catfish</title>
		<link>http://www.csharp411.com/convert-binary-to-base64-string/comment-page-1/#comment-5485</link>
		<dc:creator>John Catfish</dc:creator>
		<pubDate>Thu, 13 May 2010 15:53:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/convert-binary-to-base64-string/#comment-5485</guid>
		<description>I think you could replace the method 
&quot;static private char SixBitToChar( byte b )&quot;
for an array.

It should be faster. It has no method call overhead, no ifs, no calculations, it is readonly and it only implies an access operation [].

string Dict = &quot;ABCDE....abc...etc&quot;

So instead of SixBitToChar(b)
you should do Dict[b]</description>
		<content:encoded><![CDATA[<p>I think you could replace the method<br />
"static private char SixBitToChar( byte b )"<br />
for an array.</p>
<p>It should be faster. It has no method call overhead, no ifs, no calculations, it is readonly and it only implies an access operation [].</p>
<p>string Dict = "ABCDE&#8230;.abc&#8230;etc"</p>
<p>So instead of SixBitToChar(b)<br />
you should do Dict[b]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damian</title>
		<link>http://www.csharp411.com/convert-binary-to-base64-string/comment-page-1/#comment-5266</link>
		<dc:creator>Damian</dc:creator>
		<pubDate>Tue, 25 Aug 2009 08:48:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/convert-binary-to-base64-string/#comment-5266</guid>
		<description>Hi - This is a gret post that I have found extremely helpful.

I am using Base 64 to create shorter URLs as described, and I&#039;m not too familiar with all the maths of bytes and bases.

Public Shared Function encUC(ByVal uniqueCode As String) As String

        Dim val As Int64 = Convert.ToInt64(uniqueCode)
        Dim retVal As String

        Dim tinyByte() = System.BitConverter.GetBytes(val)

        &#039;NB THIS WILL WORK FOR A MAX OF 12 DIGIT CODES
        &#039;ReDim Preserve tinyByte(4)

        Dim tinyCode = Base64.Base64Encoder.ToBase64(tinyByte)

        retVal = Replace(tinyCode, &quot;=&quot;, &quot;_&quot;)
        retVal = Replace(retVal, &quot;/&quot;, &quot;-&quot;)
        retVal = Replace(retVal, &quot;+&quot;, &quot;&#124;&quot;)

        Return retVal

    End Function

When I encode it seems to not give me the least possible characters in the base64 string

eg 

1000001728 encodes as wNCaOwAAAAA_

So i have shortened the byte array :
ReDim Preserve tinyByte(4)

Which is fine as my codes are a max of 12 digits, but not very elegant.

Can you suggest anything?

ALSO

When I decode a 32 bit integer (8 digit code)

Public Shared Function decUC(ByVal encCode As String) As String

        Dim repCode As String = encCode
        repCode = Replace(repCode, &quot;_&quot;, &quot;=&quot;)
        repCode = Replace(repCode, &quot;-&quot;, &quot;/&quot;)
        repCode = Replace(repCode, &quot;&#124;&quot;, &quot;+&quot;)

        Dim origByte(7) As Byte
        origByte = Base64.Base64Encoder.FromBase64(repCode)
        ReDim Preserve origByte(7)

        Return System.BitConverter.ToInt64(origByte, 0)

    End Function

 if I don&#039;t use ReDim Preserve origByte(7) it gives me an exception on the 

Return System.BitConverter.ToInt64(origByte, 0) (array to short)

As I won&#039;t always know if i&#039;m getting an 8 or 12 digital code - I want my functions to cater for both. Any ideas?

My thanks again for a really great post that ended hours of midnight hunting  :)</description>
		<content:encoded><![CDATA[<p>Hi &#8211; This is a gret post that I have found extremely helpful.</p>
<p>I am using Base 64 to create shorter URLs as described, and I'm not too familiar with all the maths of bytes and bases.</p>
<p>Public Shared Function encUC(ByVal uniqueCode As String) As String</p>
<p>        Dim val As Int64 = Convert.ToInt64(uniqueCode)<br />
        Dim retVal As String</p>
<p>        Dim tinyByte() = System.BitConverter.GetBytes(val)</p>
<p>        'NB THIS WILL WORK FOR A MAX OF 12 DIGIT CODES<br />
        'ReDim Preserve tinyByte(4)</p>
<p>        Dim tinyCode = Base64.Base64Encoder.ToBase64(tinyByte)</p>
<p>        retVal = Replace(tinyCode, "=", "_")<br />
        retVal = Replace(retVal, "/", "-")<br />
        retVal = Replace(retVal, "+", "|")</p>
<p>        Return retVal</p>
<p>    End Function</p>
<p>When I encode it seems to not give me the least possible characters in the base64 string</p>
<p>eg </p>
<p>1000001728 encodes as wNCaOwAAAAA_</p>
<p>So i have shortened the byte array :<br />
ReDim Preserve tinyByte(4)</p>
<p>Which is fine as my codes are a max of 12 digits, but not very elegant.</p>
<p>Can you suggest anything?</p>
<p>ALSO</p>
<p>When I decode a 32 bit integer (8 digit code)</p>
<p>Public Shared Function decUC(ByVal encCode As String) As String</p>
<p>        Dim repCode As String = encCode<br />
        repCode = Replace(repCode, "_", "=")<br />
        repCode = Replace(repCode, "-", "/")<br />
        repCode = Replace(repCode, "|", "+")</p>
<p>        Dim origByte(7) As Byte<br />
        origByte = Base64.Base64Encoder.FromBase64(repCode)<br />
        ReDim Preserve origByte(7)</p>
<p>        Return System.BitConverter.ToInt64(origByte, 0)</p>
<p>    End Function</p>
<p> if I don't use ReDim Preserve origByte(7) it gives me an exception on the </p>
<p>Return System.BitConverter.ToInt64(origByte, 0) (array to short)</p>
<p>As I won't always know if i'm getting an 8 or 12 digital code &#8211; I want my functions to cater for both. Any ideas?</p>
<p>My thanks again for a really great post that ended hours of midnight hunting  <img src='http://www.csharp411.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
