user1231229
user1231229

Reputation: 61

convert text hex to real hex representation C++

I have the following file format | 00 00 07 09 | for example in a text file I need for a way to parse it so that each time I find a string between "|" convert the inside to real hex representation

for instance | 30 | will give me 0 how can it be done in C++ (damn C# makes you so lazy and dump).

this is the common format of the file

+++ath

|FF F4 FF FD 06|

/viewsource/template.html?

NAMENAME

|FF FF FF FF FF FF|

|13|

|05|

|00 00 00 08|

|00|

|0A|

|00 00|

c|82|Sc

=

GET

FTP|3A|/

|01 06 00 00 00|

HTTP/

PROPFIND

each line will be saved in a vector array that will be passed to the following function.

void WuManber::Initialize( const vector<const char *> &patterns, 
                  bool bCaseSensitive, bool bIncludeSpecialCharacters, bool       bIncludeExtendedAscii )

Upvotes: 1

Views: 488

Answers (1)

user1127914
user1127914

Reputation:

use stringstream

#include <sstream>
using namespace std;

void foo()
{
    istringstream ss("30");
    int i;
    ss >> hex >> i;
}

Upvotes: 3

Related Questions