Char[] array to int

Hi All,

I am trying to pass a value to an integer variable.
My source value is in a char array like:
char s[10];
My destination is an integer like:
int d;

Also,
the values in s are Hex values such as,

s[0] = 0A,
s[1] = E2,
etc…

Suppose i only want to pass two of them, say Sum of the decimal equivalent of s[3] and s[4] into d.

s[3] = A0 -> 160
s[4] = E2 -> 226

so, d should be 160+226

how will i do that in Dynamic C 9.52?

kindly respond.

[QUOTE=#NewRab;1181]Hi All,

I am trying to pass a value to an integer variable.
My source value is in a char array like:
char s[10];
My destination is an integer like:
int d;

Also,
the values in s are Hex values such as,

s[0] = 0A,
s[1] = E2,
etc…

Suppose i only want to pass two of them, say Sum of the decimal equivalent of s[3] and s[4] into d.

s[3] = A0 -> 160
s[4] = E2 -> 226

so, d should be 160+226

how will i do that in Dynamic C 9.52?

kindly respond.[/quote]

Make sure that s[] is an unsigned char array, then it’s simply:

unsigned char s[10];
int d;

d = s[3] + s[4];

Good luck!

Thank you! that works!!