Reputation: 5961
i tried converting this code from c#
a += (uint)(url[k + 0] + (url[k + 1] << 8) + (url[k + 2] << 16) + (url[k + 3] << 24));
to vb,net i get this
a += CUInt(url(k + 0) + (url(k + 1) << 8) + (url(k + 2) << 16) + (url(k + 3) << 24))
an i get this error
Operator '<<' is not defined for types 'Char' and 'Integer'.
Can anyone help me with a correction
EDIT
uint a, b;
a = b = 0x9E3779B9;
url = string
Upvotes: 1
Views: 1407
Reputation: 3147
http://msdn.microsoft.com/en-us/library/7haw1dex%28v=vs.71%29.aspx be sure that you use supported types.
Upvotes: 0
Reputation: 8242
I don't know VB but I would suspect you can just cast each url(k+n) first i.e.
(CUint(url(k+2))<< 8)
I'm also assuming a CUint is 32 bits Assuming you are trying to create a 32 bit int out of 4 chars there is probably more checking you can do but at a minimum I would turn this into two methods ConvertCharArrayToUint() and another one that does each shift ShiftCharLeft(char, numBits) and hide all the casting ugliness in there. I'm surprised in C# you can shift a char like that.
EDIT: Try doing this on separate lines while you're figuring it out
int part_0 = Val(url(k));
int part_1 = Val(url(k+1));
int part_2 = Val(url(k+2));
...
int shifted_1 = part_1 << 8;
...
int result = part_0 + shifted_1...
They you can step through with the debugger, check types etc and get a full understanding of what is going on, then you can refactor for whatever readability you prefer.
Upvotes: 1
Reputation: 273244
Your main problem seems to be that C# will allow bit-shifting on a char whereas VB does not.
So you would need something like (untested)
CUInt( ... + (CUint( url(k + 1) ) << 8) + ... )
But it does look like a rather weak HashCode.
Upvotes: 3