![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
FRANCESC Guest
|
Conversion Number to String |
Posted: Sat Jul 12, 2003 2:03 am |
|
|
Hi all, I use 16F873 and try to make a routine to convert a 8 bits number to an string.
Please help me how make that routine.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515900 |
|
![](templates/subSilver/images/spacer.gif) |
R.J.Hamlett Guest
|
Re: Conversion Number to String |
Posted: Sat Jul 12, 2003 2:18 am |
|
|
:=Hi all, I use 16F873 and try to make a routine to convert a 8 bits number to an string.
:=Please help me how make that routine.
sprintf
The answer depends on what sort of string you want. Your number could be (if unsigned), a value from 0-255. If signed, it could have a value from -127 to +128. You could have a series of different possible representations:
x.. (with the number of digits changing according to the size of the number).
xxx (with a fixed 'three digit' field - beware some CCS compiler versions have problems properly handling lgenerating the leading zeros...).
The same with a leading 'sign' for a signed number.
HH - the same number represented in HEX (again with the same possibilities for leading zeros or not).
C - The 8 bits output as a single character.
All these formats are supported by the sprintf command.
So:
char MyString[8];
/*The string _must_ be large enough to contain everything. Remember there is the end of string character as well. */
int val;
//A suitable 'test' number
val=100;
sprintf(MyString,"\%u",val);
The string now contains the ascii representation of the number. In this case the digits '100', followed by the 'null' terminator character.
Read the manual for 'printf', to find out all the possible 'format' strings.
Seriously, if you have to ask this, you need to get a book on 'C', and do some very basic reading...
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515901 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Conversion Number to String |
Posted: Sat Jul 12, 2003 2:21 am |
|
|
:=Hi all, I use 16F873 and try to make a routine to convert a 8 bits number to an string.
:=Please help me how make that routine.
------------------------------------------------
Use the sprintf() function for this. See the CCS manual for
information on that function.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515902 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|