ascii string to hex number conversion API

  • Thread starter Chinmoy Mukherjee
  • Start date
C

Chinmoy Mukherjee

Hi All,
Is there any api available for converting ascii string to a hexadecimal
number?
Regards,
Chinmoy
 
S

Sharad Kala

Chinmoy Mukherjee said:
Hi All,
Is there any api available for converting ascii string to a hexadecimal
number?

Why hexadecimal ? How does it matter ?

Is it only for display purposes ? If yes, you can easily do this --

cout << hex << i;

Sharad
 
H

Howard

Sharad Kala said:
Why hexadecimal ? How does it matter ?

Is it only for display purposes ? If yes, you can easily do this --

cout << hex << i;

Sharad

That outputs an integer in hex format. I believe the question asked how to
convert a string, not how to convert an integer.

To the OP:

You need to explain what you want better. Specifically, what is the ascii
string you start with, and what do you mean by a hexadecimal "number"?

What are you starting with, and what do you want to end up with? For
example, is your starting string a string that represents an integer (like
"1234")? And do you want to end up with a string that represents that
number in hex (which would be "04D2" in this case)?

If that's what you're trying to do, then first you need to convert the
string to an integer, and then convert it back to a string, except in hex
format.

Finally, we need to know how the input and output strings are stored/used.
For example, if you're just outputting the hex string, then Sharad's example
works for the output part. But if you need to store it in a C-style array,
or in a std::string, then you need something different. Similarly,
conversion of the input string also depends on how it's stored (i.e., a
C-style string or a std::string).

Let us know more precisely what you need, (if this hasn't been enough help
for you yet).

-Howard
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top