Mega Code Archive

 
Categories / VB.Net / Development
 

Use Convert ToUInt16 to convert hex String to UInt16

Module Example    Public Sub Main()       Dim hexStrings() As String = { "-13", "9", "FFFF" }       For Each hexString As String In hexStrings          Try             Dim number As UShort = Convert.ToUInt16(hexString, 16)             Console.WriteLine("Converted '{0}' to {1:N0}.", hexString, number)          Catch e As Exception             Console.WriteLine("Exception")          End Try       Next                                                End Sub End Module