Tayfur Well-Known Member Licensed User Longtime User Jun 28, 2019 #1 Buffer() As Byte is >> "192.168.1.123" (this is 13byte) And I want use and convert like it Dim b() As Byte = Array As Byte(192, 168, 1, 123) how can i convert?
Buffer() As Byte is >> "192.168.1.123" (this is 13byte) And I want use and convert like it Dim b() As Byte = Array As Byte(192, 168, 1, 123) how can i convert?
janderkan Well-Known Member Licensed User Longtime User Jun 28, 2019 #2 b(0) = (Buffer(1)-48)*100 + (Buffer(1)-48)*10 + (Buffer(2)-48 if b(x)= 46 -> advance to next Upvote 0
Tayfur Well-Known Member Licensed User Longtime User Jun 28, 2019 #3 janderkan said: b(0) = (Buffer(1)-48)*100 + (Buffer(1)-48)*10 + (Buffer(2)-48 if b(x)= 46 -> advance to next Click to expand... sorry ı dont understand. buffer length is 13 Upvote 0
janderkan said: b(0) = (Buffer(1)-48)*100 + (Buffer(1)-48)*10 + (Buffer(2)-48 if b(x)= 46 -> advance to next Click to expand... sorry ı dont understand. buffer length is 13
janderkan Well-Known Member Licensed User Longtime User Jun 28, 2019 #4 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
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
M Mostez Well-Known Member Licensed User Longtime User Jun 29, 2019 #5 output looks like this: AppStart 192 168 1 123 Code: Copy 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
output looks like this: AppStart 192 168 1 123 Code: Copy 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
Tayfur Well-Known Member Licensed User Longtime User Jul 1, 2019 #6 Mostez said: output looks like this: AppStart 192 168 1 123 Code: Copy 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 Click to expand... 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/ Code: Copy 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
Mostez said: output looks like this: AppStart 192 168 1 123 Code: Copy 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 Click to expand... 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/ Code: Copy 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.
M Mostez Well-Known Member Licensed User Longtime User Jul 1, 2019 #7 yes, to convert integer(or any number) to string use NumberFormat, to convert byte array or string to integer use Bit.ParseInt Upvote 0
yes, to convert integer(or any number) to string use NumberFormat, to convert byte array or string to integer use Bit.ParseInt