<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog of Travis Hydzik &#187; string</title>
	<atom:link href="http://thydzik.com/tag/string/feed/" rel="self" type="application/rss+xml" />
	<link>http://thydzik.com</link>
	<description>random snippets and information</description>
	<lastBuildDate>Mon, 30 Apr 2012 15:46:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Decimal to Binary functions in Visual Basic</title>
		<link>http://thydzik.com/decimal-to-binary-functions-in-visual-basic/</link>
		<comments>http://thydzik.com/decimal-to-binary-functions-in-visual-basic/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 11:16:00 +0000</pubDate>
		<dc:creator>thydzik</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[16 bit]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[decimal]]></category>
		<category><![CDATA[signed integer]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://thydzik.com/?p=563</guid>
		<description><![CDATA[Here are functions to perform decimal to/from binary conversion. CBin &#8211; converts a decimal integer to binary string. CDeci &#8211; converts a binary string to decimal integer. CBinS16 &#8211; converts a decimal signed integer to 16 bit binary string. CdecS16 &#8211; converts a 16 bit binary string to decimal signed integer.<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/decimal-to-binary-functions-in-visual-basic/' addthis:title='Decimal to Binary functions in Visual Basic ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Here are functions to perform decimal to/from binary conversion.</p>
<ul>
<li>CBin &#8211; converts a decimal integer to binary string.</li>
<li>CDeci &#8211; converts a binary string to decimal integer.</li>
<li>CBinS16 &#8211; converts a decimal signed integer to 16 bit binary string.</li>
<li>CdecS16 &#8211; converts a 16 bit binary string to decimal signed integer.</li>
</ul>
<pre class="brush: vb; title: ; notranslate">
'converts an integer to binary string
Function CBin(ByVal n As Double) As String
    On Error Resume Next 'caters for 0 values
    Dim i As Double
    i = 2 ^ Int(Log(n) / Log(2))
    Do While i &gt;= 1
        CBin = CBin &amp; Fix(n / i)
        n = n - i * Fix(n / i)
        i = i / 2
    Loop
End Function

'converts a binary string to integer
Function CDeci(ByRef s As String) As Double
    Dim i As Long
    CDeci = 0
    For i = 0 To Len(s) - 1
        CDeci = CDeci + (Mid$(s, Len(s) - i, 1) * 2 ^ i)
    Next i
End Function

'converts an integer to 16 bit signed binary string
Function CBinS16(ByVal n As Double) As String
    Dim i As Double

    CBinS16 = vbNullString
    If n &lt; -2 ^ 15 Then
        CBinS16 = &quot;0&quot;
        n = n + 2 ^ 16
        i = 2 ^ 14
    ElseIf n &lt; 0 Then
        CBinS16 = &quot;1&quot;
        n = n + 2 ^ 15
        i = 2 ^ 14
    Else 'not negative
        i = 2 ^ 15
    End If

    Do While i &gt;= 1
        CBinS16 = CBinS16 &amp; Fix(n / i)
        n = n - i * Fix(n / i)
        i = i / 2
    Loop
End Function

'converts 16 bit signed binary string to integer
Function CDecS16(ByRef s As String) As Double
    Dim i As Long
    CDecS16 = 0
    For i = 0 To Len(s) - 1
        CDecS16 = CDecS16 + (Mid$(s, Len(s) - i, 1) * 2 ^ i)
    Next i
    If CDecS16 &gt;= 2 ^ 15 Then 'negative number
        CDecS16 = CDecS16 - 2 ^ 16
    End If
End Function
</pre>
<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/decimal-to-binary-functions-in-visual-basic/' addthis:title='Decimal to Binary functions in Visual Basic ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://thydzik.com/decimal-to-binary-functions-in-visual-basic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimizing/faster String Concatenation in VBA</title>
		<link>http://thydzik.com/optimizingfaster-string-concatenation-in-vba/</link>
		<comments>http://thydzik.com/optimizingfaster-string-concatenation-in-vba/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 00:12:37 +0000</pubDate>
		<dc:creator>thydzik</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[concatenation]]></category>
		<category><![CDATA[faster]]></category>
		<category><![CDATA[optimizing]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://thydzik.com/?p=248</guid>
		<description><![CDATA[There are numerous links about Visual Basic string concatenation, one particular is Microsoft&#8217;s How To Improve String Concatenation Performance. But the article is overwritten for the point it is trying to make, so I will share a simplified example. Lets say we want to perform the following concatenation: This takes approximately 6000 ticks. The faster [...]<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/optimizingfaster-string-concatenation-in-vba/' addthis:title='Optimizing/faster String Concatenation in VBA ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>There are numerous links about Visual Basic string concatenation, one particular is Microsoft&#8217;s <a title="How To Improve String Concatenation Performance" href="http://support.microsoft.com/kb/170964" target="_blank">How To Improve String Concatenation Performance</a>. But the article is overwritten for the point it is trying to make, so I will share a simplified example.</p>
<p>Lets say we want to perform the following concatenation:</p>
<pre class="brush: vb; title: ; notranslate">
Dim i As Long
Dim s As String
For i = 1 To 100000000
	s = &quot;A&quot; &amp; i &amp; &quot;B&quot;
Next i
</pre>
<p>This takes approximately 6000 ticks. The faster approach, yet more complex functionality would be as follows:</p>
<pre class="brush: vb; title: ; notranslate">
Dim sourceLength As Long
sourceLength = 1
Dim source As String
s = &quot;A B&quot;

Dim i As Long
Dim s As String
For i = 1 To 100000000
	source = CStr(i)
	If Len(source) &gt; sourceLength Then
		sourceLength = Len(source)
		s = &quot;A&quot; &amp; Space$(sourceLength) &amp; &quot;B&quot;
	End If
	Mid$(s, 2, sourceLength) = source
Next i
</pre>
<p>Which takes approximately 3700 ticks, a saving of nearly 40%.</p>
<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/optimizingfaster-string-concatenation-in-vba/' addthis:title='Optimizing/faster String Concatenation in VBA ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://thydzik.com/optimizingfaster-string-concatenation-in-vba/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Object Caching 543/543 objects using disk: basic
Content Delivery Network via t01.thydzik.com

Served from: thydzik.com @ 2012-05-23 09:49:46 -->
