locked
Converting numbers to hex

    Question

  • So I admit, my googling skills are horrid. I Would like to know how to convert a number to it's hexidecimal equivalent. I'm working with numbers with a range of 1000 to about 1200 or so. I will be creating a unique numerical ID system for created NPC's in a game, and hex takes up less space and memory in a text save file.

    Thanks in advance!

    Saturday, June 02, 2007 3:04 AM

Answers

  •  Otomno wrote:

    So I admit, my googling skills are horrid. I Would like to know how to convert a number to it's hexidecimal equivalent. I'm working with numbers with a range of 1000 to about 1200 or so. I will be creating a unique numerical ID system for created NPC's in a game, and hex takes up less space and memory in a text save file.

    Thanks in advance!

    Code Snippet

     

    Dim hexString As String

    Dim myInt As Integer

    hexString = Hex(myInt)

    'It will work for an SByte, Byte, Short, UShort

    ' Integer, Uinteger,Long, Ulong and Object types.

     

     

     

    Regards,

     

    S_DS

     

    Saturday, June 02, 2007 3:13 AM
  • You can do this as well...

     

    Code Snippet

     

    Dim i As Int16 = 15

    i.ToString("x")

     

    Edit: and this turns the hex back to a number, which you'll want to know as well

    Code Snippet

     

    Int16.TryParse(s, Globalization.NumberStyles.HexNumber, Nothing, i)

     

    Saturday, June 02, 2007 11:05 AM

All replies

  •  Otomno wrote:

    So I admit, my googling skills are horrid. I Would like to know how to convert a number to it's hexidecimal equivalent. I'm working with numbers with a range of 1000 to about 1200 or so. I will be creating a unique numerical ID system for created NPC's in a game, and hex takes up less space and memory in a text save file.

    Thanks in advance!

    Code Snippet

     

    Dim hexString As String

    Dim myInt As Integer

    hexString = Hex(myInt)

    'It will work for an SByte, Byte, Short, UShort

    ' Integer, Uinteger,Long, Ulong and Object types.

     

     

     

    Regards,

     

    S_DS

     

    Saturday, June 02, 2007 3:13 AM
  • You can do this as well...

     

    Code Snippet

     

    Dim i As Int16 = 15

    i.ToString("x")

     

    Edit: and this turns the hex back to a number, which you'll want to know as well

    Code Snippet

     

    Int16.TryParse(s, Globalization.NumberStyles.HexNumber, Nothing, i)

     

    Saturday, June 02, 2007 11:05 AM