View previous topic :: View next topic |
Author |
Message |
Kookoo Guest
|
Hexadecimal to character Conversion |
Posted: Tue Jan 24, 2006 3:18 am |
|
|
Hello,
is there any function to convert a hexadecimal number to a character ?
Or to convert an ASCII number to a character ?
Many Thanks. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Tue Jan 24, 2006 8:59 am |
|
|
What do you mean by character?
What are you trying to do. Be specific. |
|
|
Kasper
Joined: 14 Jan 2004 Posts: 88 Location: Aurora, Ontario, Canada
|
|
Posted: Tue Jan 24, 2006 9:46 am |
|
|
something more than what the printf function does? |
|
|
KamPutty Guest
|
Re: Hexadecimal to character Conversion |
Posted: Tue Jan 24, 2006 10:24 am |
|
|
Kookoo wrote: | Hello,
is there any function to convert a hexadecimal number to a character ?
Or to convert an ASCII number to a character ?
Many Thanks. |
Hi there,
If you mean that you have a value of lets say "0xFF" and you want to print it in hex and not decimal, you do have some options...
use the "%x|X" in printf (can apply to sprintf) etc.
~or~
create an array with the 16 values 0,1,2,3,4...f
then use the high and low nibbles to obtain that value in ascii
char_array[(value&0xf0)>>4] // high character
char_array[(value%0x0f)] // low character
make sense?
~Kam (^8* |
|
|
KamPutty Guest
|
Re: Hexadecimal to character Conversion |
Posted: Tue Jan 24, 2006 10:26 am |
|
|
Kookoo wrote: | Hello,
is there any function to convert a hexadecimal number to a character ?
Or to convert an ASCII number to a character ?
Many Thanks. |
Hi there,
If you mean that you have a value of lets say "0xFF" and you want to print it in hex and not decimal, you do have some options...
use the "%x|X" in printf (can apply to sprintf) etc.
~or~
create an array with the 16 values 0,1,2,3,4...f
then use the high and low nibbles to obtain that value in ascii
char_array[(value&0xf0)>>4] // high character
char_array[(value%0x0f)] // low character
make sense?
~Kam (^8* |
|
|
|