Create a negative hexadecimal value out of range of the Long type. : Hex « Data Types « VB.Net






Create a negative hexadecimal value out of range of the Long type.

 


Module Example
   Public Sub Main()
        Dim sourceNumber As ULong = ULong.MaxValue
        Dim isSigned As Boolean = Math.Sign(sourceNumber.MinValue) = -1
        Dim value As String = sourceNumber.ToString("X")
        Dim targetNumber As Long
        Try
           targetNumber = Convert.ToInt64(value, 16)
           If Not isSigned And ((targetNumber And &H8000000000) <> 0) Then
              Throw New OverflowException()
           Else 
              Console.WriteLine("0x{0} converts to {1}.", value, targetNumber)
           End If    
        Catch e As OverflowException
           Console.WriteLine("Unable to convert '0x{0}' to a long integer.", value)
        End Try 
   End Sub
End Module

   
  








Related examples in the same category

1.Data type: Long, Char, Hex and OctData type: Long, Char, Hex and Oct
2.Create a negative hexadecimal value out of range of the Long type.
3.Create a negative hexadecimal value out of range of the Byte type.
4.Create a hexadecimal value out of range of the Integer type.
5.Create a negative hexadecimal value out of range of the UInt16 type.
6.Parse Hex number in string to Integer and catch OverflowException
7.Display value as hexadecimal
8.Display value with eight hexadecimal digits