const char* to hex char

  • Thread starter Philliam Auriemma
  • Start date
P

Philliam Auriemma

Hey guys,

Say I have a const char* that equals "10". How would I go about
turning that into '\x10'? I've tried itoa and ssprintf or something,
and have been at it for an entire day but I can't figure it out.
 
J

Jerry Coffin

Hey guys,

Say I have a const char* that equals "10". How would I go about
turning that into '\x10'? I've tried itoa and ssprintf or something,
and have been at it for an entire day but I can't figure it out.

This will convert the string to an unsigned long, assuming the input
is in hexadecimal:

unsigned long value = strtoul("10", NULL, 16);

Printing that value back out in hexadecimal with a leading '0x' looks
something like:

std::cout << std::hex << std::showbase << value << "\n";
 
P

Philliam Auriemma

This will convert the string to an unsigned long, assuming the input
is in hexadecimal:

unsigned long value = strtoul("10", NULL, 16);

Printing that value back out in hexadecimal with a leading '0x' looks
something like:

std::cout << std::hex << std::showbase << value << "\n";

WOW THANK YOU, this is a life saver. Perfect.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top