B4R Question Bad Results from ByteConverter

thali

Member
Licensed User
Longtime User
I get strange results from ByteConverter:
1683783575535.png
what is the problem?
 
Solution
I get strange results from ByteConverter:
View attachment 141921what is the problem?
Try this code
B4X:
    Dim floatStr As String = "12.34"
    Log("float$=",floatStr)
    Log("isNrF$? ", IsNumber(floatStr))
    Dim bc As ByteConverter
    Dim f As Float = bc.StringFromBytes(floatStr)
    Log("f=",f)
    Log("+++++++++++++++++++++++++++++++")
    Dim intStr As String = "123"
    Log("int$=",intStr)
    Log("isNrI$? ", IsNumber(intStr))
    Dim i As Int = bc.StringFromBytes(intStr)
    Log("i=",i)

thali

Member
Licensed User
Longtime User
unfortunately not:
Dim floatStr As String = "12.34"
also won't work. (I have to process ascii characters from stream of bytes)
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Have you tried
B4X:
Dim floatStr() As Byte = "12.34".GetBytes

(I can't test it as I have just discovered I have no com ports on my laptop so can't run B4R lol)
 
Upvote 0

thali

Member
Licensed User
Longtime User
Thank you all for the hints!
I also cleaned the project but the output still was the same.
Running the test code on an other board(M5Stack-Core) gives the same result.
In my project I have to parse NMEA strings comming from a GPS. According examples on this forum the code should be like this:
Code:
Dim floatStr() As Byte = "12.34"
Log("float$=",floatStr)
Log("isNrF$? ", IsNumber(floatStr))
Dim f As Float = bc.StringFromBytes(floatStr)
Log("f=",f)

Log("+++++++++++++++++++++++++++++++")

Dim intStr As String = "123"
Log("int$=",intStr)
Log("isNrI$? ", IsNumber(intStr))
Dim i As Int = bc.StringFromBytes(intStr)
Log("i=",i)

Output:
ESP-ROM:esp32c3-api1-20210207
AppStart
float$=12.34
isNrF$? 1
f=12.3400
+++++++++++++++++++++++++++++++
int$=123
isNrI$? 1
i=123
;)
 
Upvote 0

teddybear

Well-Known Member
Licensed User
I get strange results from ByteConverter:
View attachment 141921what is the problem?
Try this code
B4X:
    Dim floatStr As String = "12.34"
    Log("float$=",floatStr)
    Log("isNrF$? ", IsNumber(floatStr))
    Dim bc As ByteConverter
    Dim f As Float = bc.StringFromBytes(floatStr)
    Log("f=",f)
    Log("+++++++++++++++++++++++++++++++")
    Dim intStr As String = "123"
    Log("int$=",intStr)
    Log("isNrI$? ", IsNumber(intStr))
    Dim i As Int = bc.StringFromBytes(intStr)
    Log("i=",i)
 
Upvote 0
Solution
Top