Convert unsigned char * to uint64_t

I converted uint64_t to unsigned char* using the following:

 uint64_t in; unsigned char *out; sprintf(out,"%" PRIu64, in); 

Now I want to do the opposite. Any idea?

+6
source share
1 answer

A direct analog of what you are doing with sprintf(3) would be to use sscanf(3) :

 unsigned char *in; uint64_t out; sscanf(in, "%" SCNu64, &out); 

But probably strtoull(3) will be easier and more efficient when handling errors:

 out = strtoull(in, NULL, 0); 

(This answer assumes that in does point to something similar to how out should point to something in your code example.)

+9
source

Source: https://habr.com/ru/post/953526/


All Articles