Home > Software engineering >  Hexadecimal string into an array
Hexadecimal string into an array

Time:09-28

Generated after processing inspection hexadecimal string displayed in the text, format the following "0200030 b3a00000000013231343433b903", now to a set of two characters into an array, the array should be a (0)=& amp; The H2 a (1)=& amp; H0 a (2)=& amp; H3 a (3)=& amp; HB a (4)=& amp; H3A a (5)=& amp; H0 so on

CodePudding user response:

As a C programmer, the
The scanf, sscanf, fscanf
Printf, sprintf, fprintf
Usage of this kind of function, or to do "boxing hand, curved mouth",
 # include & lt; Stdio. H> 
Char [] s="0200030 b3a00000000013231343433b903";
Char b [100];
Int I, v;
Int main () {
i=0;
While (1) {
If (1!=sscanf (s + 2 * I, "% 2 x", & amp; V)) break;
[I]=b (char) v.
i++;
If (i>=100) break;
}
N=I;
for (i=0; Ireturn 0;
}

CodePudding user response:

refer to the original poster Denessa response:
generated after processing inspection hexadecimal string displayed in the text, format the following "0200030 b3a00000000013231343433b903", now to a set of two characters into an array, the array should be a (0)=& amp; The H2 a (1)=& amp; H0 a (2)=& amp; H3 a (3)=& amp; HB a (4)=& amp; H3A a (5)=& amp; H0 so on

 Option Explicit 
Dim strHex As String

Private Sub Command1_Click ()
Dim bytHex () As Byte
Dim As Long I
ReDim bytHex (Len (strHex)/2-1)
For I=1 To Len (strHex) Step 2
BytHex ((I - 1)/2)=Val (Mid (strHex, I, 2))
Next
For I=0 To UBound (bytHex)
The Debug. Print bytHex (I)
Next
End Sub

Private Sub Form_Load ()
B3a00000000013231343433b903 strHex="0200030", "
End Sub

CodePudding user response:

Vb6, can use the mid function, this is a stupid method,
Should also can use the API, such as copymemory

CodePudding user response:

In fact, the need for hexadecimal string to a Byte array format conversion between:
 
Dim () As a Byte, I As Long
B3a00000000013231343433b903 Text1="0200030", "
ReDim a (Len (Text1) \ 2-1)
For I=0 To UBound (a)
A (I)=Val (" & amp; H "& amp; Mid (Text1, I * 2 + 1, 2))
The Debug. Print "& amp; H "& amp; Hex (a (I)) & amp; "";
Next I
The Debug. Print

Results the
 & amp; The H2 & amp; H0 & amp; H3 & amp; HB & amp; H3A & amp; H0 & amp; H0 & amp; H0 & amp; H0 & amp; H1 & amp; H32 & amp; H31 & amp; H34 & amp; H34 & amp; H33 & amp; HB9 & amp; H3 
  • Related