Android Question Hex to Decimal

kaudie

Member
Licensed User
Longtime User
Why do I get an error when I try this?

Dim Str_HexNumber As String
Str_HexNumber = "DA2DDE56"
Dim Int_Number As Int
Int_Number = Bit.ParseInt(Str_HexNumber, 16)

The error is:
java.lang.NumberFormatException: Invalid int: "DA2DDE56"

thanks
 

kaudie

Member
Licensed User
Longtime User
It give me a negative value "-634528170". With an Internet-converter I get the correct value "3660439126".
Why is that?
 
Upvote 0

James Chamblin

Active Member
Licensed User
Longtime User
It seems that ParseInt() will not work with values above $7FFFFFFF. I do know that $80000000 is greater than the maximum Int, but I would think that it would just simply roll the extra bit into the sign bit, just like this example
B4X:
    Dim Int_Number As Int = 0x80000000
    Log(Int_Number)
 
Upvote 0

James Chamblin

Active Member
Licensed User
Longtime User
typed my reply at the same time as yours. The reason that it is negative is because the largest value that can be held by an Int is 2147483647 ($7fffffff). When you write a larger value to the Int, the extra bit is written to the sign bit, giving you a negative value. Anything larger than $FFFFFFFF will most likely be truncated to the lowest 32 bits.
 
Upvote 0
Top