|
|
View previous topic :: View next topic |
Author |
Message |
PeterD Guest
|
inttoascii or hextoascii function? |
Posted: Mon Dec 16, 2002 9:17 am |
|
|
Does anyone know where I can find an inttoascii or hextoascii function?
___________________________
This message was ported from CCS's old forum
Original Post ID: 10065 |
|
|
R.J.Hamlett Guest
|
Re: inttoascii or hextoascii function? |
Posted: Mon Dec 16, 2002 9:43 am |
|
|
:=Does anyone know where I can find an inttoascii or hextoascii function?
sprintf
For your requirements:
char output[5];
sprintf(output,"\%D",value_to_convert);
Will put into the string 'output', the ASCII equivalent of the number in 'value_to_convert'. Using '\%ld', instead of '\%D', will allow a long integer to be sent. With this the output could be seven digits 'wide' ('-' sign, 5 digits, and the terminating '\0'), so the array would need to be larger.
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 10066 |
|
|
Dave Yeatman Guest
|
Re: inttoascii or hextoascii function? |
Posted: Mon Dec 16, 2002 4:07 pm |
|
|
Depending on what you are doing, converting individual numbers is easy. This would be the building block for whatever you want to do.
If a decimal digit simply add 48 to make it the ascii equivalent.
For hex:
If <=9 then add 0x30, else add 0x37.
I created a function that I call with the digit to convert and it returns a char. I also pass a boolean flag "hex" to tell whether to convert hex or decimal. Once created, the routine works everywhere and you can paste it into any code.
Example protoype:
char convert(byte digit, boolean hex)
Good Luck!
Dave
___________________________
This message was ported from CCS's old forum
Original Post ID: 10078 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|