Android Question [SOLVED] Question about "ParseInt"... or bad use of it

Luca Rinaldoni

Member
Licensed User
Hi,
I try to read UID from a tag RFID, type MIFARE Ultralight, with "Ultrareader" sample that I've found in this site.

The result of two reads are:

TAG RFID 'Ultralight'
#1
Out: 04F62F55026D3F84D448000000000000
UID: 026D3F84

#2
Out: 0454D20ACA6C3F801948000000000000
UID: CA6C3F80


The UID variable contains value of identifier that I wont convert into a number.

I had reach to parse UID of sample #1 into 'i' variable, and I obtain '40714116'.
I using this routine:

Try
Dim i As Int
i = Bit.ParseInt(strData, 16)

Log(i)
Catch
Log("Failed ParseInt: " & LastException)
End Try

The #2 case raise an exception: java.lang.NumberFormatException: Invalid int: "CA6C3F80".
I suppouse that the value of second sample return a number more big then 'int'.

Can I convert (or parse) the value on Long? Is there a function?


Thanks in advance
;)
 

Luca Rinaldoni

Member
Licensed User
Thanks Erel!
Your sample works, but I need a positive number; in C# I used Convert.Int64 like this:

B4X:
Convert.Int64("CA6C3F80", 16) => Result: 3396091776

Can I obtain a positive number with a function of ByteConverter?
I try to use this:
B4X:
            Dim idLong As Long = bc.LongsFromBytes(bc.HexToBytes(strData))(0)
            Log(idLong)
but raised an exception: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0.


Thanks for your help...
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
You are casting an int to long because bc.longsFromBytes fails, but as the int (signed in B4A) is already negative, the long will also be because of the casting
Add the bottom lines
B4X:
Dim bc As ByteConverter
Dim id As Long = bc.intsFromBytes(bc.HexToBytes("CA6C3F80"))(0)
Log(id)  '  -898875520   (in fact it is 0xFFFFFFFFCA6C3F80)
If id<0 Then id=id+4294967296   '<-- we are adding 0x100000000
Log(id)  '  3396091776
 
Upvote 0
Top