How do you convert hex to decimal using VB.NET?

后端 未结 9 1811
自闭症患者
自闭症患者 2020-12-11 03:04

I need to convert hex to a decimal in VB.NET. Found several examples in C#, but when I tried to convert to VB.NET I was not successful. An example of a hexadecimal number th

9条回答
  •  情话喂你
    2020-12-11 03:26

    That is a 24-byte (192-bit) number; what value are you expecting?

    Note that you can use Convert to do a lot of the grungy work here - for example (in C#):

        string hex = "A14152464C203230304232323020572F544947455234352E";
        byte[] raw = new byte[hex.Length / 2];
        for (int i = 0; i < raw.Length ; i++)
        {
            raw[i] = Convert.ToByte(hex.Substring(i * 2,2), 16);
        }
    

    How you get from raw to a number depends on what you think the number is...

    Visual Basic translation courtesy of .NET Reflector (although the "-1" looks odd):

    Dim hex As String = "A14152464C203230304232323020572F544947455234352E"
    Dim raw As Byte() = New Byte((hex.Length / 2)  - 1) {}
    Dim i As Integer
    For i = 0 To raw.Length - 1
        raw(i) = Convert.ToByte(hex.Substring((i * 2), 2), &H10)
    Next i
    

提交回复
热议问题