0
Dim A As String = String.Join("", "1F", "40")
Dim B As Integer = Convert.TonInt32(A,16) 

return 8000.

My Questions

  1. How to convert into hex in VB if my decimal value is in negative (i.e. -8000 or -80 as for example)?
  2. How to convert into negative value in VB if a hex value of EE6C

Thank you for your help.

Joey
  • 3
  • 2
  • The [Convert.ToString Method](https://learn.microsoft.com/en-us/dotnet/api/system.convert.tostring?view=netframework-4.8) method has overloads which can convert to a base-16 string, e.g. `Console.WriteLine(Convert.ToString(-1000S, 16))` outputs "fc18". – Andrew Morton Apr 11 '20 at 12:03
  • That great. It work. What is the meaning of the S after -1000? is that represent -1000 is in string? How about to do the opposite? If I have "fc18", how can I convert it into negative value? – Joey Apr 11 '20 at 12:18
  • It's to force it to be a Short instead of Integer: [Forced literal types](https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/data-types/type-characters). If you look around in the Convert class I linked to before, you'll find the method you need: `Convert.ToInt16`. – Andrew Morton Apr 11 '20 at 13:42

0 Answers0