<?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: Calculating CRC-32 in C# and .NET</title>
	<atom:link href="http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net/feed" rel="self" type="application/rss+xml" />
	<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net</link>
	<description>A .NET developer in Redmond</description>
	<lastBuildDate>Sun, 14 Mar 2010 14:22:22 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: ASP.NET Performance - Part 3 - Cache Busting - Karl Seguin - CodeBetter.Com - Stuff you need to Code Better!</title>
		<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net#comment-34252</link>
		<dc:creator>ASP.NET Performance - Part 3 - Cache Busting - Karl Seguin - CodeBetter.Com - Stuff you need to Code Better!</dc:creator>
		<pubDate>Mon, 11 Jan 2010 13:53:45 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2006/08/08/calculating_crc32_in_c_and_net.aspx#comment-34252</guid>
		<description>[...] of our asset folder) and hash values. For my &quot;hash&quot; I&#039;m using a CRC32, specifically Damien Guard&#039;s C# implementation. The nice thing about CRC32 is that we end up with pretty small values. The downside is that [...]</description>
		<content:encoded><![CDATA[<p>[...] of our asset folder) and hash values. For my &quot;hash&quot; I&#39;m using a CRC32, specifically Damien Guard&#39;s C# implementation. The nice thing about CRC32 is that we end up with pretty small values. The downside is that [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net#comment-30448</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Thu, 19 Nov 2009 23:00:04 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2006/08/08/calculating_crc32_in_c_and_net.aspx#comment-30448</guid>
		<description>Any chance you could update the sample usage?  Things appear to have changed since it was written...

-M</description>
		<content:encoded><![CDATA[<p>Any chance you could update the sample usage?  Things appear to have changed since it was written&#8230;</p>
<p>-M</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damien Guard</title>
		<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net#comment-17656</link>
		<dc:creator>Damien Guard</dc:creator>
		<pubDate>Wed, 20 May 2009 06:36:47 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2006/08/08/calculating_crc32_in_c_and_net.aspx#comment-17656</guid>
		<description>You can&#039;t really do that - the whole idea of a checksum is that if a single byte changes or is transferred incorrectly then the checksum fails - if you only checksum every 1 byte in 100 then it&#039;s not going to catch 99% of the errors.

[)amien</description>
		<content:encoded><![CDATA[<p>You can&#8217;t really do that &#8211; the whole idea of a checksum is that if a single byte changes or is transferred incorrectly then the checksum fails &#8211; if you only checksum every 1 byte in 100 then it&#8217;s not going to catch 99% of the errors.</p>
<p>[)amien</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: camillo</title>
		<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net#comment-17123</link>
		<dc:creator>camillo</dc:creator>
		<pubDate>Wed, 13 May 2009 08:42:12 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2006/08/08/calculating_crc32_in_c_and_net.aspx#comment-17123</guid>
		<description>How to speed up calculation?
On 20GB files it takes a lot...
Do you think can be done something like spot calculation?
Say 1 byte every 100 bytes?

Camillo</description>
		<content:encoded><![CDATA[<p>How to speed up calculation?<br />
On 20GB files it takes a lot&#8230;<br />
Do you think can be done something like spot calculation?<br />
Say 1 byte every 100 bytes?</p>
<p>Camillo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sph3re</title>
		<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net#comment-10975</link>
		<dc:creator>Sph3re</dc:creator>
		<pubDate>Fri, 30 Jan 2009 16:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2006/08/08/calculating_crc32_in_c_and_net.aspx#comment-10975</guid>
		<description>I think that returning it as a BigEndian Byte array is a mistake since 98% of .NET code is running on windows based systems (which use the Little-Endian method).

also, reading every byte from the result array, formatting it to &quot;x2&quot; and adding it into a string is expensive and causing you to construct 5 strings (1 empty, and another one for each byte you append the formatted output).

I think that adding something like this would benefit everyone more.. (after returning little endian byte arrays) :)
&lt;pre class=&quot;code csharp&quot;&gt;&lt;b&gt;public static string&lt;/b&gt; FormatCRC32Result(&lt;b&gt;byte&lt;/b&gt;[] result) {
   &lt;b&gt;if&lt;/b&gt; (!BitConverter.IsLittleEndian) {
      Array.Reverse(result);
   }
   &lt;b&gt;return&lt;/b&gt; BitConverter.ToUInt32(result, 0).ToString(&quot;X8&quot;).ToLower();
}&lt;/code&gt;&lt;/pre&gt;

PS – thx for the kickass implementation :)
PS #2 – it works fine on Vista ultimate x64</description>
		<content:encoded><![CDATA[<p>I think that returning it as a BigEndian Byte array is a mistake since 98% of .NET code is running on windows based systems (which use the Little-Endian method).</p>
<p>also, reading every byte from the result array, formatting it to &#8220;x2&#8243; and adding it into a string is expensive and causing you to construct 5 strings (1 empty, and another one for each byte you append the formatted output).</p>
<p>I think that adding something like this would benefit everyone more.. (after returning little endian byte arrays) :)</p>
<pre class="code csharp"><b>public static string</b> FormatCRC32Result(<b>byte</b>[] result) {
   <b>if</b> (!BitConverter.IsLittleEndian) {
      Array.Reverse(result);
   }
   <b>return</b> BitConverter.ToUInt32(result, 0).ToString("X8").ToLower();
}</pre>
<p>PS – thx for the kickass implementation :)<br />
PS #2 – it works fine on Vista ultimate x64</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alessio</title>
		<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net#comment-10410</link>
		<dc:creator>Alessio</dc:creator>
		<pubDate>Tue, 25 Nov 2008 11:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2006/08/08/calculating_crc32_in_c_and_net.aspx#comment-10410</guid>
		<description>Hi,
I tried to execute the program under Windows XP and the CRC-hash calculated for a file of 25MB wasn&#039;t correct, just because of in windows XP the CalculateHash was called more than once(it works with a lenght of 4096 byte at a time). I toke off the &#039;~&#039; from &quot;return ~crc&quot; of CalculateHash and put it on &quot;byte[] hashBuffer = UInt32ToBigEndianBytes(~hash)&quot; of HashFinal, so that step was made only once at the end of cycle (without modifying the intermediate values).
In this way the algorithm worked corrctly.

I hope I gived a hand,
Alessio</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I tried to execute the program under Windows XP and the CRC-hash calculated for a file of 25MB wasn&#8217;t correct, just because of in windows XP the CalculateHash was called more than once(it works with a lenght of 4096 byte at a time). I toke off the &#8216;~&#8217; from &#8220;return ~crc&#8221; of CalculateHash and put it on &#8220;byte[] hashBuffer = UInt32ToBigEndianBytes(~hash)&#8221; of HashFinal, so that step was made only once at the end of cycle (without modifying the intermediate values).<br />
In this way the algorithm worked corrctly.</p>
<p>I hope I gived a hand,<br />
Alessio</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stefan</title>
		<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net#comment-9146</link>
		<dc:creator>stefan</dc:creator>
		<pubDate>Fri, 15 Aug 2008 15:06:20 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2006/08/08/calculating_crc32_in_c_and_net.aspx#comment-9146</guid>
		<description>Did you fix the error in your code now? I would like to use it, with files longer than 4096 bytes.</description>
		<content:encoded><![CDATA[<p>Did you fix the error in your code now? I would like to use it, with files longer than 4096 bytes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damien Guard</title>
		<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net#comment-6461</link>
		<dc:creator>Damien Guard</dc:creator>
		<pubDate>Thu, 28 Feb 2008 13:43:44 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2006/08/08/calculating_crc32_in_c_and_net.aspx#comment-6461</guid>
		<description>You&#039;re right, multiple calls to HashCore will carry on from the final complement instead of the actual current hash value.

Removing the ~ complement from the CalculateHash function means you can&#039;t use that static method directly... I think complementing it in Initialize and inside HashCore might be a better approach.

Will update the code once I&#039;ve had chance to test it and check the other hashing algorithms I have up.

Thanks!

[)amien</description>
		<content:encoded><![CDATA[<p>You&#8217;re right, multiple calls to HashCore will carry on from the final complement instead of the actual current hash value.</p>
<p>Removing the ~ complement from the CalculateHash function means you can&#8217;t use that static method directly&#8230; I think complementing it in Initialize and inside HashCore might be a better approach.</p>
<p>Will update the code once I&#8217;ve had chance to test it and check the other hashing algorithms I have up.</p>
<p>Thanks!</p>
<p>[)amien</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mario</title>
		<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net#comment-6460</link>
		<dc:creator>Mario</dc:creator>
		<pubDate>Thu, 28 Feb 2008 13:26:37 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2006/08/08/calculating_crc32_in_c_and_net.aspx#comment-6460</guid>
		<description>Nice code, but i found a bug if you compute values for streams larger than 4096 bytes (make textfile in sample code larger than 4096). In this case the HashCore function is called more than once but the complement is build in the CalculateHash function. So you don&#039;t get the complement for the final value but for each intermediate value which will result in a wrong value. The complement build should take place in the HashFinal function.</description>
		<content:encoded><![CDATA[<p>Nice code, but i found a bug if you compute values for streams larger than 4096 bytes (make textfile in sample code larger than 4096). In this case the HashCore function is called more than once but the complement is build in the CalculateHash function. So you don&#8217;t get the complement for the final value but for each intermediate value which will result in a wrong value. The complement build should take place in the HashFinal function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gaurav</title>
		<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net#comment-5770</link>
		<dc:creator>Gaurav</dc:creator>
		<pubDate>Tue, 01 Jan 2008 16:30:26 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2006/08/08/calculating_crc32_in_c_and_net.aspx#comment-5770</guid>
		<description>]Dude, thanks a lot, i found a lot of dumb code out there and this is the best code written for this purpose.

I wrote one my self but it was a conversion from Java to c# and i did not use at least some support which c# provides and there was some other code which generated wrong checksomes on a 64-bit processor.
Although i have not tested your code on 64 bit processor but it seems it should work fine as far as my knowledge is concerned.</description>
		<content:encoded><![CDATA[<p>]Dude, thanks a lot, i found a lot of dumb code out there and this is the best code written for this purpose.</p>
<p>I wrote one my self but it was a conversion from Java to c# and i did not use at least some support which c# provides and there was some other code which generated wrong checksomes on a 64-bit processor.<br />
Although i have not tested your code on 64 bit processor but it seems it should work fine as far as my knowledge is concerned.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Calculating CRC-64 in C# and .NET &#187; DamienG</title>
		<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net#comment-5195</link>
		<dc:creator>Calculating CRC-64 in C# and .NET &#187; DamienG</dc:creator>
		<pubDate>Mon, 19 Nov 2007 12:53:43 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2006/08/08/calculating_crc32_in_c_and_net.aspx#comment-5195</guid>
		<description>[...] how the CRC-32 C# class I posted some time ago continues to get lots of Google hits I thought I&#039;d post a CRC-64 version which will no doubt be far [...]</description>
		<content:encoded><![CDATA[<p>[...] how the CRC-32 C# class I posted some time ago continues to get lots of Google hits I thought I&#8217;d post a CRC-64 version which will no doubt be far [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damien Guard</title>
		<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net#comment-1547</link>
		<dc:creator>Damien Guard</dc:creator>
		<pubDate>Sun, 29 Oct 2006 11:40:37 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2006/08/08/calculating_crc32_in_c_and_net.aspx#comment-1547</guid>
		<description>Updated to include usage sample.

[)amien</description>
		<content:encoded><![CDATA[<p>Updated to include usage sample.</p>
<p>[)amien</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ronak</title>
		<link>http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net#comment-1546</link>
		<dc:creator>Ronak</dc:creator>
		<pubDate>Sat, 28 Oct 2006 08:14:41 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2006/08/08/calculating_crc32_in_c_and_net.aspx#comment-1546</guid>
		<description>But how do i use it in the Actual Code.&lt;br /&gt;I want to calculate CRC of file...&lt;br /&gt;How can i use this code to do it</description>
		<content:encoded><![CDATA[<p>But how do i use it in the Actual Code.<br />I want to calculate CRC of file&#8230;<br />How can i use this code to do it</p>
]]></content:encoded>
	</item>
</channel>
</rss>
