convert HEX string to Decimal in arduino -
i have hex string : "0005607947" , want convert decimal number , test on this site , correctly convert decimal number , answer : "90208583" when use code wrong value ! of code wrong or did have 1 , new code problem ?
long int decimal_answer = getdec("0005607947") ; long int getdec(string str110) { long int id = 0 ; int len = str110.length() ; char buff[len] ; int power = 0 ; for(int = 0 ; <len ; i++) { buff[i] = str110.charat(i); } for(int = (len-1) ; >=0 ; i--) { int num = buff[i] - '0' ; id = id + num * pow(16 , power) ; power = power + 1 ; } serial.println(string(id , dec)); return id ; } // , use , error : invalid conversion 'void*' 'char**' [-fpermissive] unsigned int size = sizeof(f_value) ; char charbuf[size]; f_value.tochararray(charbuf , size); long decimal_answer = strtol(charbuf , null , 16); serial.println(decimal_answer , dec);
drop code, , use 'strtol' standard library.
#include <stdlib.h> long strtol (const char *__nptr, char **__endptr, int __base)
for use:
long decimal_answer = strtol("0005607947", null, 16);
Comments
Post a Comment