I got errors when trying to convert an "ABC" value to Int, using this sample code:
Source: https://www.b4x.com/android/forum/threads/b4x-hex-string-to-number.122739/#content
I found this reference:
I actually believe that the IntsFromBytes function should complement the missing bytes so that the value could be obtained.
But as this does not happen, there is an adaptation so that the input variable has the correct formatting:
B4X:
Sub StringToInt(Str As String) As Int
Dim converter As ByteConverter
Dim ii() As Int = converter.IntsFromBytes(converter.HexToBytes(Str))
Return ii(0)
End Sub
Source: https://www.b4x.com/android/forum/threads/b4x-hex-string-to-number.122739/#content
I found this reference:
Source: https://www.b4x.com/android/forum/t...r-not-returning-array-of-ints.115710/#contentthe IntsFromBytes (which expects 4 bytes per int).
I actually believe that the IntsFromBytes function should complement the missing bytes so that the value could be obtained.
But as this does not happen, there is an adaptation so that the input variable has the correct formatting:
B4X:
Sub StringToInt(Str As String) As Int
If Str.Length = 0 Or Str.Length > 8 Then
Return 0
End If
If Str.Length <> 8 Then
For i = Str.Length To 7
Str = "0" & Str
Next
End If
Dim converter As ByteConverter
Dim ii() As Int = converter.IntsFromBytes(converter.HexToBytes(Str))
Return ii(0)
End Sub