CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Conversion Number to String

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
FRANCESC
Guest







Conversion Number to String
PostPosted: Sat Jul 12, 2003 2:03 am     Reply with quote

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
R.J.Hamlett
Guest







Re: Conversion Number to String
PostPosted: Sat Jul 12, 2003 2:18 am     Reply with quote

:=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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Conversion Number to String
PostPosted: Sat Jul 12, 2003 2:21 am     Reply with quote

:=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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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