In C#
or VB.NET
how I can retrieve the low-order DWORD
of an Int64
value without Casting the value?
I've read this SO question but stills unclear to me, I work with VB.NET
, anyways an answer says:
in many languages, all you need to do is cast it to an Int32. The top bits will be discarded.
This seems that works in C#
just casting it to Integer:
((int)LongValue)
But in VB.NET
seems not 'cause I've tried to cast it and I get a typicall arithmetic overflow exception.
I have a method like this to get a low order word of an Integer
:
Public Shared Function GetLoWord(ByVal value As Integer) As Short
If Value And &H8000I Then
Return CShort(Value Or &HFFFF0000I)
Else
Return CShort(Value And &HFFFFI)
End If
End Function
And now I would like to write the same method for a Long
, to retrieve the low-DWORD
, so how I can continue writting this?:
''' <summary>
''' Gets the low-order double word of an 'Int64' value.
''' </summary>
''' <param name="Value">Indicates the 'Int64' value that contains both the LoDword and the HiDword.</param>
''' <returns>The return value is the low-order double word.</returns>
Public Shared Function GetLoDword(ByVal value As Long) As Integer
' Code goes here...
End Function