hello ive just got done searching google and what i found didnt work the way i need it to
i want to be able to pull a string from serial such as "a90" and have it converted to a hex value like 0xa90
ive tryed
//Start Hex String To Int
int x2i(char *s)
{
int x = 0;
for(;;) {
char c = *s;
if (c >= '0' && c <= '9') {
x *= 16;
x += c - '0';
}
else if (c >= 'A' && c <= 'F') {
x *= 16;
x += (c - 'A') + 10;
}
else break;
s++;
}
return x;
}
//End Hex String To Int
but it returns 0 for all input
ive gotten this code to convert string to decmal but i need it to be hex no decnal i dont want to have to type dec numbers into the serial port
//Start String To Int
int stringToNumber(String thisString) {
int i, value, length;
length = thisString.length();
char blah[(length+1)];
for(i=0; i<length; i++) {
blah[i] = thisString.charAt(i);
}
blah[i]=0;
value = atoi(blah);
return value;
}
//End String TO Int
this is a little frushtrating but can anyone give me some help converting a serial string or any string to HEX thank you in advance for your help