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
Author Message
raman00084@gmail.com

Joined: 28 Jul 2014
Posts: 35

 converting hexadecimal to decimal value Posted: Sat Jul 24, 2021 1:55 am char gps_buf[]={"GPGGA,000044.262,,,,,0,0,,,M,,M,,*4E"}; in the array the last 2 characters is the check sum value ( 4E) HOW CAN I CONVERT THE LAST 2 CHARACTERS TO DECIMAL VALUE FOR EXAMPLE CHAR CHECK_SUM[3]={0} CHECK_SUM[0]='4'; CHECK_SUM[1]='E'; HOW TO CONVERT THIS TO DECIMAL VALUE THAT IS 78 KINDLY HELP.
temtronic

Joined: 01 Jul 2010
Posts: 8220
Location: Greensville,Ontario

 Posted: Sat Jul 24, 2021 4:39 am quick reply.. CCS supplies the function ATOI(). If you open the manual, it's listed and the example program 'input.c' shows how to use it. jay
Ttelmah

Joined: 11 Mar 2010
Posts: 17477

Posted: Sat Jul 24, 2021 10:45 am

Though atoi is supplied, it is quite a complex way of doing the conversion.
Easier to just use a simple convert and multiply on the characters. So:
 Code: int htodec(char c) {     if(c >= '0' && c<= '9')        return c-'0';     if(c >= 'A' && c <= 'F')        return c-55;     if (c >= 'a' && c <= 'f')        return c-87;     return 0; //Impossible character } //then for the locations of the '4E': val=htodec(gps_buf[34])*16+htodec(gps_buf[35]);

Should give the value in decimal.
I think I've counted the locations correctly (do check...).

This is faster and smaller than using atoi
temtronic

Joined: 01 Jul 2010
Posts: 8220
Location: Greensville,Ontario

 Posted: Sun Jul 25, 2021 5:13 am Hey Mr. T.... Using Notepad+, I get 35, and 36 as the locations. BUT...that's really 34 and 35 as we have to start at ZERO for arrays. In QB45 you could use either '0' or '1' as the starting cell. Jay
Ttelmah

Joined: 11 Mar 2010
Posts: 17477

 Posted: Sun Jul 25, 2021 6:57 am Cor, I counted right!... I was just counting characters on a laptop.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT - 6 Hours Page 1 of 1

 Jump to: Select a forum Software----------------General CCS C DiscussionCode LibraryEZ App LynxBest OfKnown Issues Hardware----------------CCS ICD / Mach X / Load-n-Go
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