I am trying to convert string value into its hex form, but not able to do.
Following is the C++ code snippet, with which I am trying to do.
#include <stdio.h>
#include <sys/types.h>
#include <string>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
using namespace std;
int main()
{
string hexstr;
hexstr = "000005F5E101";
uint64_t Value;
sscanf(hexstr.c_str(), "%" PRIu64 "", &Value);
printf("value = %" PRIu64 " \n", Value);
return 0;
}
The Output is only 5, which is not correct.
Any help would be highly appreciated.
Thanks,
Yuvi
If you’re writing C++, why would you even consider using
sscanfandprintf? Avoid the pain and just use astringstream: