Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27034

VS 2010 [RESOLVED] HEX Values

$
0
0
Hi
Been trying with some converion of Hex numbers. One confusing thing for me is negative Hex values.

Let say:
Code:

Dim intResult As Integer
        intResult = Int32.Parse("FFa4", Globalization.NumberStyles.HexNumber)
        txtSum.Text = intResult 'Returns 65444

But what I know should it be -92.

Or
Code:

txtSum.Text = "FFa4"
        txtSum.Text = Convert.ToInt32(txtSum.Text, 16) 'returns 65444

But this returns the negative number:
Code:

Dim a As String = "&HFFa4"
        Dim b As Integer
        b = CInt(IIf(CInt("&H" & a.Substring(2, 1)) > 7 And a.Length = 6, "&HFFFFFFFFFFFF" & a.Substring(2), a))
        txtSum.Text = b 'Returns -92

Any other suggestions, or good explainations. I guess that there are better things but using the old IIF function...

Viewing all articles
Browse latest Browse all 27034

Trending Articles