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

Char to Hex Conversion

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







Char to Hex Conversion
PostPosted: Fri Nov 30, 2007 5:23 am     Reply with quote

example:

dataout="0942"

I need to convert "0942" to 0x0942

Thanks for your help.
Foppie



Joined: 16 Sep 2005
Posts: 138
Location: The Netherlands

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Fri Nov 30, 2007 6:24 am     Reply with quote

check the manual for the atoi(), atol() and atoi32() functions.
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

PostPosted: Fri Nov 30, 2007 8:02 am     Reply with quote

Just happen to have this, from a recent project. It works, but is not guaranteed bullet-proof Smile -Ken
(dbyte is a double-byte)

Code:

dbyte   atox (char *p)
{
    static  char Hex[] = "0123456789ABCDEF";
    dbyte   result;

    result = 0;
    while ( *p && strchr(Hex,*p) ) {
        result <<= 4;
        if ( *p < 'A' )
            result += *p - '0';
        else result += *p - ('A' - 10);
        p++;
    }
    return result;
}

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