Dim str As String = "0x33303a43363a46373a30303a39353a3641"
Dim BC As ByteConverter
Dim data() As Byte = BC.HexToBytes(str.SubString(2))
Dim sData As String = ""
For Each b As Byte In data
sData=sData & chr(b)
Next
Log(sData)
you have to remove "0x"Hi everyone...
i've this string
0x33303a43363a46373a30303a39353a3641
that represents some bytes.. how can i transform it in actual bytes?
i tried with for loops, byteconverter, arrays etc... nothing works like I need...
Dim str As String = "0x33303a43363a46373a30303a39353a3641"
Dim BC As ByteConverter
Dim data() As Byte = BC.HexToBytes(str.SubString(2))
Log((str.Length-2)/2)
Log(str)
Log(data.Length)
Dim sData As String = ""
For Each b As Byte In data
sData=sData & b & " "
Next
Log(sData)
LOG
17
0x33303a43363a46373a30303a39353a3641
17
51 48 58 67 54 58 70 55 58 48 48 58 57 53 58 54 65
Thanks for the answer but this is not what I meant..you have to remove "0x"
B4X:Dim str As String = "0x33303a43363a46373a30303a39353a3641" Dim BC As ByteConverter Dim data() As Byte = BC.HexToBytes(str.SubString(2)) Log((str.Length-2)/2) Log(str) Log(data.Length) Dim sData As String = "" For Each b As Byte In data sData=sData & b & " " Next Log(sData)
LOG
17
0x33303a43363a46373a30303a39353a3641
17
33 30 3a 43 36 3a 46 37 3a 30 30 3a 39 35 3a 36 41
Do you want it in hex?Thanks for the answer but this is not what I meant..
i mean that the result should be:
B4X:LOG 17 0x33303a43363a46373a30303a39353a3641 17 33 30 3a 43 36 3a 46 37 3a 30 30 3a 39 35 3a 36 41
otherwise the result is:
View attachment 130311
instead of:
View attachment 130312
Dim str As String = "0x33303a43363a46373a30303a39353a3641"
Dim BC As ByteConverter
Dim data() As Byte = BC.HexToBytes(str.SubString(2))
Log((str.Length-2)/2)
Log(str)
Log(data.Length)
Dim sData As String = ""
For Each b As Byte In data
sData=sData & BC.HexFromBytes(Array As Byte (b)) & " "
Next
Log(sData)
17
0x33303a43363a46373a30303a39353a3641
17
33 30 3A 43 36 3A 46 37 3A 30 30 3A 39 35 3A 36 41
Dim str As String = "0x33303a43363a46373a30303a39353a3641"
str=str.SubString(2)
Dim HexString(str.Length/2) As String
Dim sData As String = ""
For i=0 To str.Length-1 Step 2
HexString(i/2)=str.SubString2(i,i+2)
sData=sData & HexString(i/2) & " "
Next
Log(sData)
What I need is to convert the String "0x33303a43363a46373a30303a39353a3641" into an Byte Array containg the exact same numbers etc, not their representation in byte.. i don't know if i explained it very well...But what exactly do you want to achieve?
Unfortunately, it is not always easy to understand the matter. I'm sorry, I answered for what I understand.What I need is to convert the String "0x33303a43363a46373a30303a39353a3641" into an Byte Array containg the exact same numbers etc, not their representation in byte.. i don't know if i explained it very well...
the end result is to convert this string "0x33303a43363a46373a30303a39353a3641" to this "30:C6:F7:00:95:6A" using then ByteToString
PS. Maybe you meant StringFromBytesto this "30:C6:F7:00:95:6A" using then ByteToString
There is a pattern because "3A" in hex is the ":" character... infact that bytes represent a MAC AddressIt looks like a pattern of 5 digit numbers and then separate by a letter “a”.
Don't worry. Thanks to you in any case for your time.Unfortunately, it is not always easy to understand the matter. I'm sorry, I answered for what I understand.
To me a Byte Array is a set of Bytes, and that's what you get in the first example.
Maybe you want a specific type of representation of this ByteArray.
More than this I don't know how to help you because I'm not sure I understand correctly
Can't you just insert colon at regular intervals every 2 characters?Don't worry. Thanks to you in any case for your time.
I try to explain better.
Like the number 1 can be represented in various way:
"1" (String)
1 (Int)
0x01 (Hex)
Also what I (unfortunately) have is a Byte Array but for ugly reasons is represented in String.
So i need
"0x33303a43363a46373a30303a39353a3641" (String) ------ become ----> Array as Byte (33, 30, 3a, 43, 36, 3a, 46, 37, 3a, 30, 30, 3a, 39, 35, 3a, 36, 41)
In this manner i can take them and put inside ByteToString(bytes, 0, length, "UTF8") and finally get ---> "30:C6:F7:00:95:6A" (String)
Dim str As String = "0x33303a43363a46373a30303a39353a3641"
str=str.SubString(2)
Dim sData As String = ""
For i=0 To str.Length-1 Step 2
sData=sData & str.SubString2(i,i+2) & ":"
Next
Log(sData)
But.. in this way the result wouldn't be --> "33:30:3a:43:36:3a:46:37:3a:30:30:3a:39:35:3a:36:41"?Can't you just insert colon at regular intervals every 2 characters?
So like
B4X:Dim str As String = "0x33303a43363a46373a30303a39353a3641" str=str.SubString(2) Dim sData As String = "" For i=0 To str.Length-1 Step 2 sData=sData & str.SubString2(i,i+2) & ":" Next Log(sData)
Only now I understand what you want to achieve.But.. in this way the result wouldn't be --> "33:30:3a:43:36:3a:46:37:3a:30:30:3a:39:35:3a:36:41"?
Dim str As String = "0x33303a43363a46373a30303a39353a3641"
Dim BC As ByteConverter
Dim data() As Byte = BC.HexToBytes(str.SubString(2))
Dim sData As String = ""
For Each b As Byte In data
sData=sData & chr(b)
Next
Log(sData)
Ouh... i did't know about ChrI haven't tried it but it should work. Only now did I understand that they were ascii codes of the string
B4X:Dim str As String = "0x33303a43363a46373a30303a39353a3641" Dim BC As ByteConverter Dim data() As Byte = BC.HexToBytes(str.SubString(2)) Dim sData As String = "" For Each b As Byte In data sData=sData & chr(b) Next Log(sData)