View previous topic :: View next topic |
Author |
Message |
raman00084@gmail.com
Joined: 28 Jul 2014 Posts: 38
|
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: 9228 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: 19515
|
|
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: 9228 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: 19515
|
|
Posted: Sun Jul 25, 2021 6:57 am |
|
|
Cor, I counted right!...
I was just counting characters on a laptop. |
|
|
|