Conversion Hex string to ASCII value
-
Dear All, I have some problem in converting Hex string to ASCII value. For example, I have Hex string of "50" and I would like to display the ASCII equivalent "P". If i know the value to convert i can just use CString str; str = "\x50"; to convert to ASCII value. But the Hex value is entered by the user. So I dont know how to do that. Can Anyone please help me in this? Thanks in Advance.
Regards, Ram
-
Dear All, I have some problem in converting Hex string to ASCII value. For example, I have Hex string of "50" and I would like to display the ASCII equivalent "P". If i know the value to convert i can just use CString str; str = "\x50"; to convert to ASCII value. But the Hex value is entered by the user. So I dont know how to do that. Can Anyone please help me in this? Thanks in Advance.
Regards, Ram
Would
::strtol()
help you in this situation? Info here.[^]
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
-
Would
::strtol()
help you in this situation? Info here.[^]
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
Can you please give me an example?
Regards, Ram
-
Can you please give me an example?
Regards, Ram
Ram Murali wrote:
Can you please give me an example?
:confused: I provided a link in my previous post to MSDN. Follow it and you will find another link in the MSDN article to an example.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
-
Ram Murali wrote:
Can you please give me an example?
:confused: I provided a link in my previous post to MSDN. Follow it and you will find another link in the MSDN article to an example.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
But this function is to convert str to long. how can i get a character?
Regards, Ram
-
But this function is to convert str to long. how can i get a character?
Regards, Ram
-
But this function is to convert str to long. how can i get a character?
Regards, Ram
Ram Murali wrote:
But this function is to convert str to long.
Of course; and that return value is the ASCII code for the character. E.g. if your user has input "50" the
long
return value of::strtol()
will be 0x50, which is 80 in decimal format, and this is the ASCII character code for 'P'.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
-
Dear All, I have some problem in converting Hex string to ASCII value. For example, I have Hex string of "50" and I would like to display the ASCII equivalent "P". If i know the value to convert i can just use CString str; str = "\x50"; to convert to ASCII value. But the Hex value is entered by the user. So I dont know how to do that. Can Anyone please help me in this? Thanks in Advance.
Regards, Ram
Ram Murali wrote:
For example, I have Hex string of "50" and I would like to display the ASCII equivalent "P".
CString strHex = "0x50";
char *pEnd;
printf("%c\n", strtol(strHex, &pEnd, 16));
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Ram Murali wrote:
For example, I have Hex string of "50" and I would like to display the ASCII equivalent "P".
CString strHex = "0x50";
char *pEnd;
printf("%c\n", strtol(strHex, &pEnd, 16));
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
Thanks a lot. Its working well.
Regards, Ram
-
Ram Murali wrote:
But this function is to convert str to long.
Of course; and that return value is the ASCII code for the character. E.g. if your user has input "50" the
long
return value of::strtol()
will be 0x50, which is 80 in decimal format, and this is the ASCII character code for 'P'.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
Thanks for your effort to solve my problem. Its working well. Thanks again.
Regards, Ram