Newbie question
I try to conver 03E2EE47722C to a number using GEOint=Bit.ParseInt("03E2EE47722C",16) but get an error.
I try to conver 03E2EE47722C to a number using GEOint=Bit.ParseInt("03E2EE47722C",16) but get an error.
Dim GEOint As Long = ParseLong( "03E2EE47722C",16)
Sub ParseLong(Number As String, Radix As Int) As Long
Dim jo As JavaObject
jo.InitializeStatic("java.lang.Long")
Return jo.RunMethod("parseLong", Array As Object(Number, Radix))
End Sub
Dim l As Long, s, sl, sr As String
s = "003E2EE47722C"
Do While s.CharAt(0) = "0"
s = s.SubString(1)
Loop
If s.Length > 6 Then
sl = s.SubString2(0, 6)
sr = s.SubString(6)
Else
sl = "0"
sr = s
End If
l = Bit.ParseInt(sl ,16) * Power(2, sr.Length*4) + Bit.ParseInt(sr ,16)
Log (sl & " " & sr)
Log(NumberFormat(l, 0, 0))
That value is too big to hold in an Int. You can use a Long or a Double like this
B4X:Dim l As Long, s, sl, sr As String s = "003E2EE47722C" Do While s.CharAt(0) = "0" s = s.SubString(1) Loop If s.Length > 6 Then sl = s.SubString2(0, 6) sr = s.SubString(6) Else sl = "0" sr = s End If l = Bit.ParseInt(sl ,16) * Power(2, sr.Length*4) + Bit.ParseInt(sr ,16) Log (sl & " " & sr) Log(NumberFormat(l, 0, 0))
Hello Erel,The value is too large for Int.
You can use this code:
B4X:Dim GEOint As Long = ParseLong( "03E2EE47722C",16) Sub ParseLong(Number As String, Radix As Int) As Long Dim jo As JavaObject jo.InitializeStatic("java.lang.Long") Return jo.RunMethod("parseLong", Array As Object(Number, Radix)) End Sub