Convert C # code to VB.NET

I tried to convert this code from C #

a += (uint)(url[k + 0] + (url[k + 1] << 8) + (url[k + 2] << 16) + (url[k + 3] << 24));

in 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

The operator '<is not defined for the types "Char" and "Integer".

Can someone help me with the fix

EDIT

uint a, b;

a = b = 0x9E3779B9;

url = string

+1
source share
3 answers

Your main problem is that C # allows bit offsets to char, while VB doesn't.

So you need something like (untested)

 CUInt( ... + (CUint( url(k + 1) ) << 8) + ... )

But it looks like a pretty weak HashCode.

+3
source

I do not know VB, but I suspect that you can simply sketch each url (k + n) first i.e.

(CUint(url(k+2))<< 8)

, CUint 32 , 32- int 4- , , , , , ConvertCharArrayToUint() , ShiftCharLeft (char, numBits ) . , # char.

: , .

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...

, .. , , , .

+1

All Articles