Hi,
I'm writing a memory analyzer for Keil uVision to display memory usage instead of having to wade through map files.
I wish to convert a string of the form: 0xhhhhhhhh to a long integer so I can do calc's. I also wish to convert the result back to hex strings.
Of course I strip off the 0x and make the remaining 8 char's upper case.
The problem I have is I don't get the answer I expect: viz
Input 0x0807dc74 = 134,732,916 decimal
But the output I get is 8,597,713,124 decimal = 0x2 0076 B0E4 in Hex
I have fiddled with the Endianess and tried bytes and strings, but with no success.
I feel it's got something to do with two's complement, but I am not sure what. It is making my brain hurt.
Can someone help me.
The code in question is:
Regards
Rob
I'm writing a memory analyzer for Keil uVision to display memory usage instead of having to wade through map files.
I wish to convert a string of the form: 0xhhhhhhhh to a long integer so I can do calc's. I also wish to convert the result back to hex strings.
Of course I strip off the 0x and make the remaining 8 char's upper case.
The problem I have is I don't get the answer I expect: viz
Input 0x0807dc74 = 134,732,916 decimal
But the output I get is 8,597,713,124 decimal = 0x2 0076 B0E4 in Hex
I have fiddled with the Endianess and tried bytes and strings, but with no success.
I feel it's got something to do with two's complement, but I am not sure what. It is making my brain hurt.
Can someone help me.
The code in question is:
Convert hex string to long integer:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private Button1 As B4XView
Private Answer As Long
Private textOPDecimal As TextArea
Private txtInputHex As TextArea
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
End Sub
Sub Button1_Click
If txtInputHex.Text = "" Then
textOPDecimal.Text = 0/0
Return
End If
Answer = HexToInt(txtInputHex.Text)
textOPDecimal.Text = Answer
End Sub
Private Sub HexToInt(hexStr As String) As Long
Dim bc As ByteConverter
Dim RegionUsed As Long
Dim tempStr As String
Dim tempByte(8) As Byte
tempStr = hexStr.ToUpperCase
bc.LittleEndian = False
tempByte = bc.StringToBytes(tempStr, "UTF8")
RegionUsed = Bit.ParseLong(bc.StringFromBytes(tempByte, "UTF8"), 32)
' RegionUsed = Bit.ParseLong(tempStr, 32)
Return RegionUsed
End Sub
Regards
Rob