Home > Back-end >  I have 11 hexadecimal number, how to spell them together?
I have 11 hexadecimal number, how to spell them together?

Time:06-05

If I have the s [11]=={0 x 5, 0 xc5, 0 xb2, 0 xea... } the number 11, how to splice them as 05 c5b3... In this form

CodePudding user response:

The use of itoa
 
#include
#include
using namespace std;
Int main () {
Int s [11] {0 x 5, 0 xc5, xb2 0, 0 xea};
Char STR [100]="";
Char TMP [10].
For (int I=0; I & lt; 4. I++)
Sprintf (& amp; STR [strlen (STR)], "s" % 02, itoa (s [I], TMP, 16));
Printf (" % s ", STR);
return 0;
}

CodePudding user response:

reference 1st floor Italink response:
use itoa
 
#include
#include
using namespace std;
Int main () {
Int s [11] {0 x 5, 0 xc5, xb2 0, 0 xea};
Char STR [100]="";
Char TMP [10].
For (int I=0; I & lt; 4. I++)
Sprintf (& amp; STR [strlen (STR)], "s" % 02, itoa (s [I], TMP, 16));
Printf (" % s ", STR);
return 0;
}
since already know sprintf why not directly % 02 x

CodePudding user response:

 # include 
#include
using namespace std;
Int main () {
Int s [11] {0 x 5, 0 xc5, xb2 0, 0 xea};
Char STR [100].
Char TMP [10].
STR [0]=0;
For (int I=0; I & lt; 4. I++)
Sprintf (STR, "% s % 02 x", STR, (usigned char) s [I]);
Printf (" % s ", STR);
return 0;
}

CodePudding user response:

refer to the second floor lin5161678 response:
Quote: refer to 1st floor Italink response:

The use of itoa
 
#include
#include
using namespace std;
Int main () {
Int s [11] {0 x 5, 0 xc5, xb2 0, 0 xea};
Char STR [100]="";
Char TMP [10].
For (int I=0; I & lt; 4. I++)
Sprintf (& amp; STR [strlen (STR)], "s" % 02, itoa (s [I], TMP, 16));
Printf (" % s ", STR);
return 0;
}
since already know sprintf why not directly % 02 x

I think so, too, did not use itoa necessary

 # include 
#include
using namespace std;
Int main () {
Int [] s={0 x 5, 0 xc5, xb2 0, 0 xea};
Char STR [1024]={};
For (int I=0; I & lt; ARRAYSIZE (s); I++)
Sprintf (& amp; STR [strlen (STR)], "x % 02," s [I]);
Printf (" % s ", STR);
return 0;
}

CodePudding user response:

Printf/sprinf

CodePudding user response:

refer to the second floor lin5161678 response:
Quote: refer to 1st floor Italink response:

The use of itoa
 
#include
#include
using namespace std;
Int main () {
Int s [11] {0 x 5, 0 xc5, xb2 0, 0 xea};
Char STR [100]="";
Char TMP [10].
For (int I=0; I & lt; 4. I++)
Sprintf (& amp; STR [strlen (STR)], "s" % 02, itoa (s [I], TMP, 16));
Printf (" % s ", STR);
return 0;
}
since already know sprintf why not directly % 02 x

+ +
With 0 x02x directly

CodePudding user response:

reference 1st floor Italink response:
use itoa
 
#include
#include
using namespace std;
Int main () {
Int s [11] {0 x 5, 0 xc5, xb2 0, 0 xea};
Char STR [100]="";
Char TMP [10].
For (int I=0; I & lt; 4. I++)
Sprintf (& amp; STR [strlen (STR)], "s" % 02, itoa (s [I], TMP, 16));
Printf (" % s ", STR);
return 0;
}

With % 02 x directly is ok, instead of using snprintf and itoa to complicate the problem

CodePudding user response:

I think it is ok to use a FOR,
Test_1='inflammable or explosive'
Utf-8 bytes=test_1. Encode (' ') # code do you want a long string of hexadecimal number ~ ~ ~ ~ what the hell bala bala bala...
Bytes_3=STR (bytes) # (2:1) cut off the head and tail,
Bytes_4=[] # built an empty list
For I in bytes_3:
If I=='\ \' or I=='x' :
The continue
The else: bytes_4 append (I) put things in
Bytes_5="'. Join (bytes_4) # become a thing ~
So ~ I see the great god, ~

CodePudding user response:

 
#include
#include
using namespace std;
Int main () {
Int s [11] {0 x 5, 0 xc5, xb2 0, 0 xea};
Char STR [100].
For (int I=0; I & lt; 4. I++)
Sprintf (STR + I * 2, % 02 x ", (usigned char) s [I]);
Printf (" % s ", STR);
return 0;
}

CodePudding user response:

I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related