Hi Nick,
I added few debug statements in both C# and VB.Net code. Please see the
output.
Data : 17\0x01version="1.0" encoding="utf-8"
VB.Net Code:
============
Length : 36
First Hash : 36
Intermediate Hash : 4718677, 618486431744
data[0] : 49
Intermediate Hash : 618491150476, 81066872075190272
data[1] : 55
Intermediate Hash : 81067490566340748, 353537054712791040
data[2] : 0
Intermediate Hash : 434604545279131908, 941259211282055168
data[3] : 120
Intermediate Hash : 1375863756561187124, 1844235403342118912
data[4] : 48
Intermediate Hash : 3220099159903306085, 3332680371594199040
data[5] : 49
Intermediate Hash : 6552779531497505243, 5514680524283969536
data[6] : 118
Intermediate Hash : 12067460055781474880, 8500575237681709056
data[7] : 101
<Exceptionin the 8th iteration
C# Code:
========
Length : 36
First Hash : 36
Intermediate Hash : 4718677, 618486431744
data[0] : 49
Intermediate Hash : 618491150476, 81066872075190272
data[1] : 55
Intermediate Hash : 81067490566340748, 353537054712791040
data[2] : 0
Intermediate Hash : 434604545279131908, 941259211282055168
data[3] : 120
Intermediate Hash : 1375863756561187124, 1844235403342118912
data[4] : 48
Intermediate Hash : 3220099159903306085, 3332680371594199040
data[5] : 49
Intermediate Hash : 6552779531497505243, 5514680524283969536
data[6] : 118
Intermediate Hash : 12067460055781474880, 8500575237681709056
data[7] : 101
Intermediate Hash : 2121291219753632434, 12556076597748432896
data[8] : 114
Intermediate Hash : 14677367817502065445, 17908616609003077632
data[9] : 115
Intermediate Hash : 14139240352795591566, 6368156393674637312
data[10] : 105
Intermediate Hash : 2060652672760677373, 15087140905959424000
data[11] : 111
Intermediate Hash : 17147793578720101483, 7408521081953583104
data[12] : 110
Intermediate Hash : 6109570586964133032, 2028990757499568128
data[13] : 61
Intermediate Hash : 8138561344463701194, 17642991144001601536
data[14] : 34
Intermediate Hash : 7334808414755751163, 17494393418824417280
data[15] : 49
Intermediate Hash : 6382457759870616873, 1659759033328992256
data[16] : 46
Intermediate Hash : 8042216793199609177, 7142914274266054656
data[17] : 48
Intermediate Hash : 15185131067465663867, 15600697893713215488
data[18] : 34
Intermediate Hash : 12339084887469327771, 8694451968501219328
data[19] : 32
Intermediate Hash : 2586792782260995584, 4947481731654483968
data[20] : 101
Intermediate Hash : 7534274513915479662, 4431845962614046720
data[21] : 110
Intermediate Hash : 11966120476529526481, 7374976597178318848
data[22] : 99
Intermediate Hash : 894352999998293824, 14024571425877131264
data[23] : 111
Intermediate Hash : 14918924425875425188, 6156814762711187456
data[24] : 100
Intermediate Hash : 2628995114877061133, 2468400271732637696
data[25] : 105
Intermediate Hash : 5097395386609698939, 3184508020209352704
data[26] : 110
Intermediate Hash : 8281903406819051746, 8541577074476056576
data[27] : 103
Intermediate Hash : 16823480481295108383, 340561220064903168
data[28] : 61
Intermediate Hash : 17164041701360011585, 15706883263652036608
data[29] : 34
Intermediate Hash : 14424180891302496694, 17884414382611103744
data[30] : 117
Intermediate Hash : 13861851200204048938, 6949717196525535232
data[31] : 116
Intermediate Hash : 2364824323020032656, 1612996340124483584
data[32] : 102
Intermediate Hash : 3977820663144516285, 2135460351271632896
data[33] : 45
Intermediate Hash : 6113281014416149237, 8746791831719247872
data[34] : 56
Intermediate Hash : 14860072846135397143, 3101577888347848704
data[35] : 34
Returning Hash : 14860072846135397143
"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.comwrote in
message news:O4D2Rp4nGHA.3784@TK2MSFTNGP04.phx.gbl...
Quote:
Sanjib,
>
There isn't any difference. ULong and ulong are aliases that the
VB.NET and C# compilers use for UInt64.
>
My guess for the reason you get the exception is because of differences
in the implicit conversions that VB uses vs the implicit conversions that
C# uses. However, without the inputs, it's impossible to tell.
>
Also, why are you using the Decrement method on the Interlocked class?
There is really no reason to do this.
>
Hope this helps.
>
>
--
- Nicholas Paldino [.NET/C# MVP]
-
mvp@spam.guard.caspershouse.com
>
"Sanjib Biswas" <sanjib.biswas@ieee.orgwrote in message
news:%23Naudj4nGHA.4172@TK2MSFTNGP03.phx.gbl...
Quote:
>Could anyone point out to me the difference between ulong (C#) and
>UInt64/ULong (VB.Net)? I was under the impression that both are same.
>Below C# code works fine for a particular value of 'data' (string length
>36) and initial hash value '0' whereas VB.Net code throws an exception in
>the 8th iteration, saying the data is either too large or too small for a
>Uint64. I am using VB.Net/C# 2005. Am I missing anything here?
>>
>C# Code:
>=======
>static private ulong GetULongHash( string data, ulong hash )
>{
Console.WriteLine("Length : {0}", data.Length);
Quote:
Quote:
> hash += ( hash << 13 ) + (ulong)data.Length;
Console.WriteLine("First Hash : {0}", hash);
Quote:
Quote:
>>
> for (int i = 0; i < data.Length; i++)
> {
> hash += (hash << 17) + data[i];
Console.WriteLine("Intermediate Hash : {0}, {1}", hash, (hash <<
17));
Console.WriteLine("data[{0}] : {1}", i, (0 + data[i]));
Console.WriteLine("Returning Hash : {0}", hash);
Quote:
Quote:
> return hash;
>}
>>
>VB.Net Code:
>==========
>>
>Private Shared Function GetUInt64Hash(ByVal data As String, ByVal hash As
>System.UInt64) As System.UInt64
>>
> hash += (hash << 13) + CType(data.Length, System.UInt64)
> Dim i As Integer = 0
>>
> While i < data.Length
> hash += (hash << 17) + Asc(data(i))
> System.Math.Min(System.Threading.Interlocked.Incre ment(i), i - 1)
> End While
>>
> Return hash
>>
>End Function
>>
>>
>
>