>>>>>>(1) The short way is to cast the return result to UInteger, and change the return type of GetCrc32() to UInteger
>>>>>
>>>>>IIRC you can't do that cast in VB (although you can in C# using 'unchecked')
>>>>
>>>>
>>>>Viv,
>>>>
>>>>I don't know, but I'd be very surprised if it weren't possible
>>>
>>>Just tried this which won't compile:
Dim test As UInteger = DirectCast(Int32.MaxValue, UInteger)
>>>If it was a valid cast what resulting UInteger would you expect from a negative value signed int ?
>>>In C#:
unchecked { UInt32 test = ((UInt32)Int32.MinValue); }
>yields 2147483648....
>>
>>
>>Firstly, I'm surprised that it yields an even number
>>
>>Secondly, if that's the case, I guess you'll need t check whether is was negative, and if so, set the left most bit after the 'cast'
>
>But if the signed int is negative then there is no accurate equivalent for an unsigned int ?
>I'm assuming the C# cast simple treats the 32 bits as being an unsigned value ?
>FWIW:
unchecked { Int32 test = ((Int32)UInt32.MaxValue);
>gives -1
Yes, of course, all bits set is signed -1 and unsigned the max value
When the leftmost bit is set in a signed int type, then it is considered as negative
>But if the signed int is negative then there is no accurate equivalent for an unsigned int ?
Viv, this isn't about maths. The crc32 is just a structure that is 32 bits wide
If you think about it as a signed 32 bit structure and the leftmost bit is set then the number is negative
If you look at it as an unsigned 32 bit structure, the same pattern is a number >= 0
Gregory