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

Question about function atoi_b16 in loader.c

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



Joined: 03 Dec 2008
Posts: 45

View user's profile Send private message

Question about function atoi_b16 in loader.c
PostPosted: Wed Dec 03, 2008 5:18 pm     Reply with quote

I have a question about function atoi_16(char *s ) that is in file c:\program\picc\drivers\loader.c

Please give an answer. Thanks.
I am just confused. I can not make sense of function atoi_b16(char *s).

It said this function for convert two hex characters to a int8.

if *s is a hex, I think just let it move left 4 times and let & the other one. then we can get int8.

if *s is a byte, i think we can do the same way as about then get int8.

But the program shows like this
Code:

// Convert two hex characters to a int8.
unsigned int atoi_b16(char *s) { 
   unsigned int result = 0;
   int i;

   for (i=0; i<2; i++,s++)  {
      if (*s >= 'A')
         result = 16*result + (*s) - 'A' + 10;
      else
         result = 16*result + (*s) - '0';
   }

   return(result);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 03, 2008 5:35 pm     Reply with quote

The hex values are ASCII characters. For example, the string "3A"
has two ASCII bytes in it, 0x33 and 0x41.

The purpose of the function is to convert the ASCII bytes to a binary
integer. The comment above the function should be:
Quote:
Convert two ASCII hex characters to an int8 value.
Guest








PostPosted: Thu Dec 04, 2008 11:27 am     Reply with quote

Thank you so much!!!
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