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
if the valued are in the range of 0 to 9 then i can use atoi but one value is in hexadecimal
KINDLY HELP.
Hexadecimal is base 16 so take the ASCII value of each character, subtract '0' to bring the ASCII value down to units then if the result is more than 9 (meaning it was A-F) subtract an extra 7. Then multiply the first character by 16 and add the second character.
and change the final addition to:
DecimalChecksum = (CHECK_SUM[0] * 4096) + (CHECK_SUM[1] * 256) + (CHECK_SUM[2] * 16) + CHECK_SUM[1];
Note that if you are doing this many times in your program it might be easier to use the sscanf() or strtok() functions but they might use up a lot of additional program memory.
please don´t shout in this forum = don´t use all capatial letters. Read forum rules.
****
Generally:
You don´t want to convert an "array" into an integer. Because "array" just means "multiple" of a variable.
But the variable of an array can be of any variable_type. (Char, int, float, signed or unsigned ...)
What you want to do is: Convert ASCII to binary.
You are not the first one. Thus an internet search gives me more than 16 million results.
(Now we have an additional one...)