ascii letters to numbers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ascii letters to numbers

248 Views
Skaptor
Contributor I

Hello, I´m trying to do the following:

 

May I know who to convert value from Ascii to Hexadecimal?

Example:

ABC to 41 42 43

 

I´ve tried an atoi converter, but somehow it seems to only convert numbers?


Thank you.

best regards,

Labels (1)
0 Kudos
Reply
3 Replies

bigmac
Specialist III

Hello,

 

What you seem to require, is to convert an arbitrary byte value (that may just happen to represent an ASCII character), into two hexadecimal ASCII characters, one for each nybble.  For example -

 

// Convert upper nybble to hexadecimal ASCIIbyte conv2hex_H( byte val){  val >>= 4 + '0';  if (val > '9')  val += 7;  return val;}// Convert lower nybble to hexadecimal ASCIIbyte conv2hex_L( byte val){  val &= 0x0F + '0';  if (val > '9')  val += 7;  return val;}

 

Regards,

Mac

 

0 Kudos
Reply

Skaptor
Contributor I

Hello,

 

Thank you for your help.

 

So how do I use this function, should I add the results and shift them?

 

regards

0 Kudos
Reply

Skaptor
Contributor I

Thank you very much!

0 Kudos
Reply