Target each character of a string

Im trying to change a hexadecimal number to a decimal number and the only problem i have is that i don't know how to compare one character in the string to another character. i know you can compare whole strings but i cant find anything to compare just one character at a time. If anyone knows how to or if its even possible i would appreciate it.
I think you need to give a little more detail. string[i] will give you the the (i-1)-th character of the string.
Thats what i thought but i didnt seem to work maybe its something else

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
for (int i = 0; i < length; i++)
	{
		if (hex[i] == 'A')
			sum += 160;
		else if (hex[i] == 'B')
			sum += 176;
		else if (hex[i] == 'C')
			sum += 192;
		else if (hex[i] == 'D')
			sum += 208;
		else if (hex[i] == 'E')
			sum += 224;
		else if (hex[i] == 'F')
			sum += 240;
		else if (hex[i] == 'G')
			sum += 256;
		else 
			sum += hex[i];
	}


i assumed it would work this way it would check each character and decide what it need to add
I think your problem is that you are not summing properly. Your summing code implies 'A' is worth 16010 no matter where the 'A' appears in the hex value. In other words, you are saying that 0xAB = 160+176 = 0xBA = 176+160, which is clearly wrong. You need to figure out the actual value of the hex digit based on its significance (position in the number).
O thats right i forgot about that. I feel dumb now. thanks for reminding me.
Topic archived. No new replies allowed.