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 CCS Technical Support

ASCII Number to Integer or Long Integer or Hex Number

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



Joined: 07 Sep 2003
Posts: 51

View user's profile Send private message Yahoo Messenger

ASCII Number to Integer or Long Integer or Hex Number
PostPosted: Fri Oct 15, 2004 7:52 am     Reply with quote

Hello der,

The code snippet in this topic will convert an ASCII number serial stream into an interger, or long integer or a Hex formatted number.

Code:


// convert ascii number string to integer number
unsigned int8 asciiNum2Int(unsigned int8 index)
{
   unsigned int8 n;

   n = RXbuffer[index];

   if ((n<='9')&&(n>='0'))
      return (n&0x0F);     // Pure number 0 to 9
   if ((n<='F')&&(n>='A'))
      return ((n&0x0F)+9); // Hex nnumber A to F
   if ((n<='f')&&(n>='a'))
      return ((n&0x0F)+9); // Hex in lower case

   return (0);
}

// convert ascii number to interger number
unsigned int8 ascii2int8(unsigned int8 indx)
{
   unsigned int8 cnvt=0;

   cnvt = (asciiNum2Int(indx)*10) + asciiNum2Int(indx+1);

   return(cnvt);
}

// convert ascii hex number to long integer number
unsigned int16 asciiHex2int16(unsigned int8 indx)
{
   unsigned int16 addr=0;

   addr = ((asciiNum2Int(indx))*4096) + ((asciiNum2Int(indx+1))*256) +
          (asciiNum2Int(indx+2)*16) + asciiNum2Int(indx+3);

   return(addr);
}



Hope this would be of great help to any PIC user.

////
panayig



Joined: 10 Mar 2004
Posts: 3

View user's profile Send private message

PostPosted: Fri Oct 15, 2004 10:18 am     Reply with quote

Since I requested this code from you I have to thank you here in public for your responce. Thank you rrb011270 for your help and your patience.

And I have to thank also all of you that you are so kind to answer to questions and to help other people that you dont know.

I am involved in a project and I have to learn about programming PIC the hard way that is asap. Without this forum I would have half the knowledge I have now.

I hope that one day I will be able to contribute to this forum as you all do.

Once again thank you rrb011270. Very Happy
USss
Guest







About int32
PostPosted: Fri Oct 22, 2004 10:05 am     Reply with quote

Help me with unsigned int32.
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