c++ - Converting byte array containing non-ASCII characters to a string -


i want convert byte array (containing 64 elements) looks this:

9b b4 f5 b0 67 3c f8 e1 f1 f8 02 8c b2 13 4d 66 f0 72 a0 05 ...

to string. "9bb4f5b067.....". want write byte array cfile , realized easy way convert byte array string , write content. whenever try convert array string special characters , when try write byte array directly file, see special characters written in file. suggestions please?

here code: pbsignature of type pbyte , printed this:

printf("the signature is:  "); (dword = 0 ; < cbsignature ; i++)  {     printf("%2.2x ",pbsignature[i]); }  // imprint signature crc file if (!file.open(crcfilepath, cfile::modewrite, null)) {     printf("file not opened %d\n");     goto cleanup; }  (dword = 0 ; < cbsignature ; i++)  {                //printf("size of pbsig %d , value of pbsig %d\n",sizeof(pbsignature[i]),pbsignature[i] );     file.write(&pbsignature[i],sizeof(pbsignature[i]));     //printf("%2.2x ",pbsignature[i]); } 

you want this:

unsigned char bytes[] = {0x9b, 0xb4, 0xf5, 0xb0 } ;   // array of bytes string st ; (int = 0; < sizeof(bytes)/sizeof(bytes[0]); i++) {    char buff[4];    sprintf(buff, "%02x", (unsigned char)bytes[i]) ;    st = st + buff ; } // st contains "9bb4f5b0" 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -