Hi,
When using the code below with the value1 as D it works. It Logs 20 which is correct.
However when I have value1 as Š it returns 15 when it should return 90.
Another few examples that are also failing to return the correct value:
When I have value1 as ‹ it should return 91.
When I have value1 as Œ it should return 92.
Anyone have any ideas on where I have done wrong ?
I came across this ASCII chart which shows the Š ‹ Œ etc, so I would have thought my code should have worked, but maybe I am doing something wrong: http://www.aboutmyip.com/AboutMyXApp/AsciiChart.jsp
When using the code below with the value1 as D it works. It Logs 20 which is correct.
However when I have value1 as Š it returns 15 when it should return 90.
Another few examples that are also failing to return the correct value:
When I have value1 as ‹ it should return 91.
When I have value1 as Œ it should return 92.
Anyone have any ideas on where I have done wrong ?
I came across this ASCII chart which shows the Š ‹ Œ etc, so I would have thought my code should have worked, but maybe I am doing something wrong: http://www.aboutmyip.com/AboutMyXApp/AsciiChart.jsp
B4X:
Dim value1 as string = "D"
Log((HexToLong(AsciiToHex(value1))-48)). ' logs 20 which is correct
Dim value1 as string = "Š"
Log((HexToLong(AsciiToHex(value1))-48)). ' logs 15 which is wrong and should be 90
Sub AsciiToHex (a As String) As String 'ignore
Try
Dim bc As ByteConverter
Return bc.HexFromBytes(a.GetBytes("ASCII"))
Catch
End Try 'ignore
End Sub
Private Sub HexToLong(HexStr As String) As Long 'ignore
Try
Dim Lng As Long
Dim Digit As String
Dim DigitVal As Int
For i = HexStr.Length -1 To 0 Step -1
Digit = HexStr.SubString2(i, i+1).ToUpperCase
If Not("0123456789ABCDEF".Contains(Digit)) Then
' not valid char
Return 0
End If
If Digit.CompareTo("9") > 0 Then
DigitVal = Asc(Digit) - 55
Else
DigitVal = Digit
End If
Lng = Lng + DigitVal * Power(16, HexStr.Length - 1 - i)
Next
Return Lng
Catch
Log("error: HexToLong")
End Try
End Sub