Yeah i get that part but my question is how do i do 16 ^ 1, 16 ^ 2. As far as i know there is no ^ operator and you have to use the pow function. I have tried using bitwise arithmatic and i think it works but something else is wrong with my code. It is only doing the first char entered even though i want it to start at the last index.
Code:
int hexToDecimal(char * str)
{
int i, count = 0, temp, sum = 0, j = -2;
for(i = 0; str[i] != '\0'; i++)
{
if( (str[i] < 48 || str[i] > 57) && (str[i] < 65 || str[i] > 70) && ( str[i] < 97 || str[i] > 102 ))
return -1;
count++;
}
count--;
for(count; count >= 0; count--)
{
if( str[count] >= '0' && str[count] <= '9')
temp = str[count] - 48;
else if ( str[count] >= 'A' && str[count] <= 'F')
temp = str[count] - 55;
else
temp = str[count] - 87;
for(i = 0; i < count; i++)
temp = temp * 16 << (j +2);
}
printf("%i\n", temp);
return temp;