B4R Question string to int convertion

janderkan

Well-Known Member
Licensed User
Longtime User
b(0) = (Buffer(1)-48)*100 + (Buffer(1)-48)*10 + (Buffer(2)-48

if b(x)= 46 -> advance to next
 
Upvote 0

janderkan

Well-Known Member
Licensed User
Longtime User
The Buffer will contain these 13 bytes : Array as byte(49,57,50,46,49,54,56,46,49,46,49,50,51)

First byte is hundreds, second is tenths and third is ones
So you take the value and subtract 48
b(0) = (49-48)*100 + (57-48)*10 + 50-48 = 192
 
Upvote 0

Mostez

Well-Known Member
Licensed User
Longtime User
output looks like this:

AppStart
192
168
1
123


B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Private BC As ByteConverter
   
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    SplitIP("192.168.1.123")
End Sub


Sub SplitIP(IPbuffer() As Byte )
    Dim IP(4) As Byte 
    Dim idx As Byte 'array index counter
    For Each s() As Byte In BC.Split(IPbuffer, ".") 'split string and get each byte of IP address
        Dim IPval As Byte = Bit.ParseInt(BC.StringFromBytes(s),10) 'get value
        IP(idx) = IPval 'IP array holds the four bytes of IP address
        Log(IP(idx))
        idx = idx + 1
    Next
   
End Sub
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
this great . thanks.
I thinking like your sample. Split function added.

I shearced on web for Ardiunino ide.
İt has a ".toint" function
https://circuits4you.com/2018/03/09/how-to-convert-int-to-string-on-arduino/


B4X:
Example 1: Integer to String Conversion Arduino
int a = 1234;
String myStr;
myStr = String(a);   //Converts integer to string

Example 2: String to Integer conversion Arduino
String val = “1234”;
int result = val.toInt();  //Converts string to integer



does B4R have a same fonctions.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…