简体   繁体   中英

hex represented in text to char hex

hi guys I have the following file format in hex were as each letter number is represented as following. DC-01-00-00-80-11-D9-4E-C0-A8-01-24-C0-A8-01-57-13-C4-13-C4-01-BD (read like that from text file)

now I loop line by line and the each line I do the following

this is inside for loop for each line read

istringstream ss(tempString.substr(i,2));
size_t converted;
ss >> hex >> converted;
char appended = (char)converted;
 // cout << tempString.substr(i,2)+ " "  << appended<<(int)i << (int)firstFlag<<endl;
buildString+= appended;
      i++;

now my concern is that some data from the hex file are 0x00 which are null are they added correctly. or I am missing something here.

actually those are packet traces that supposedly contain intrusions I am suppose to compare them to a pattern library that I have so I am supposed to convert them and pass them line by line to a function that takes

 Search( size_t TextLength, const char *Text, const vector<const char *> &patterns ); 

If this is just "strings" that you are reading/writing then NULL is perfectly acceptable.

Null terminated strings end in \\0 in order to mark the end of the string. Without knowing in advance the size of the string this is the best performance you can hope to achieve ( Order n ), this can be reduced somewhat if you already are aware of string size by appending the string size before the string and inserting a size token at the beginnining such as

5\\0Hello which would tell the string parser that 5 letters followed, this means the looking up is much smaller that the Order n since you no longer need to read n bytes you only read the size bytes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM