Re: dealing with hex values in c# vs VB
- From: "jamie" <strider3700@xxxxxxxxxxxxx>
- Date: Thu, 12 Jan 2006 14:08:40 -0800
The resulting CRC must match up against a CRC generated by someone elses
program so I'm stuck with this seed and algorithm. I personally would have
gone directly with the MD5 function but the choice was made long before I
started writing.
I may just DLL it but I'm curious as to where the differences in the
language are. Using the reflector program I managed to get the table
built correctly. It was a case of the hex values not directly transfering
between the languages. I'm now moving onto the second function that
actually uses the table.
the original vb
'CRC computation function
Public Function AdDDNc32(ByVal Item As String, ByVal Crc32 As Long) As Long
'Declare following variables
Dim bCharValue As Byte, iCounter As Integer, lIndex As Long
Dim lAccValue As Long, lTableValue As Long
On Error Resume Next
'Iterate through the string that is to be checksum-computed
For iCounter = 1 To Len(Item)
'Selects the current character and converts it to an ASCII value
bCharValue = Asc(Mid$(Item, iCounter, 1))
'Only update CRC for valid ASCII characters, 32 to 126
If (bCharValue > 31) And (bCharValue < 127) Then
'Right shift an Unsigned Long 8 bits
lAccValue = Crc32 And &HFFFFFF00
lAccValue = lAccValue \ &H100
lAccValue = lAccValue And &HFFFFFF
'Now select the right adding value from the holding table
lIndex = Crc32 And &HFF
lIndex = lIndex Xor bCharValue 'inverts the byte
lTableValue = Crc32Table(lIndex)
'Then mix new Crc32 value with previous accumulated Crc32 value
Crc32 = lAccValue Xor lTableValue
End If
Next
'Return new Crc32 checksum
AdDDNc32 = Crc32
End Function
The line that is causing me issues is
bCharValue = Asc(Mid$(Item, iCounter, 1))
Mid$(Item,iCounter,1) should I think turn into item.substring(icounter,1)
but I'm not sure how to recreate the Asc function or exactly what it does.
"Michael Bray" <mbray@makeDIntoDot_ctiusaDcom> wrote in message
news:Xns9749A51EB8D75mbrayctiusacom@xxxxxxxxxxxxxxxx
> "=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?="
> <pbromberg@xxxxxxxxxxxxxxxxxxx> wrote in
> news:E50877FE-7F23-4028-B483-0A0E10802AC1@xxxxxxxxxxxxx:
>
>> 1) Compile the VB.NET and use Lutz Roeder's Reflector freeware product
>> to decompile it to C#. Its' not perfect, but it works for most
>> classes.
>>
>
> Or for that matter, compile the VB.NET in a DLL and reference it. :)
>
> As an aside, if the OP is using CRC only within his own applications (ie
> not communicating with other applications that he didn't write) he could
> also use MD5.ComputeHash(...). It works nicely because you can put the
> result into a Guid.
>
> -mdb
.
- References:
- dealing with hex values in c# vs VB
- From: jamie
- RE: dealing with hex values in c# vs VB
- From: Peter Bromberg [C# MVP]
- RE: dealing with hex values in c# vs VB
- From: Michael Bray
- dealing with hex values in c# vs VB
- Prev by Date: Re: Articles or Turorials on Aggregation??
- Next by Date: Re: dealing with hex values in c# vs VB
- Previous by thread: Re: dealing with hex values in c# vs VB
- Next by thread: Re: Read a PDF file
- Index(es):
Relevant Pages
|