B4J Question Hex to number

Philip Prins

Active Member
Licensed User
Longtime User
Newbie question
I try to conver 03E2EE47722C to a number using GEOint=Bit.ParseInt("03E2EE47722C",16) but get an error.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
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
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
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))
 
Upvote 0

Philip Prins

Active Member
Licensed User
Longtime User
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))

Thanks
 
Upvote 0

Philip Prins

Active Member
Licensed User
Longtime User
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
Hello Erel,

How can i do this in B4A?

Regards
Philip
 
Upvote 0
Top