Hi all, hope you are well.
I'm having some trouble trying to convert the literal value of a hex number to int.
I say literal but I'm not sure if that is the correct term, but my code will explain better I hope.
I have simplified the code down to just my conundrum, the array is not populated in the
fashion shown but the result is the same.
definition of 'uchar' is 'unsigned char' and cannot be changed.
void testFunc00(){
char in;
const uchar i0 = '30';
const uchar i1 = '31';
const uchar i2 = '32';
const uchar i3 = '33';
const uchar i4 = '34';
const uchar i5 = '35';
const uchar i6 = '36';
const uchar i7 = '37';
const uchar i8 = '38';
const uchar i9 = '39';
uchar auChars [10] = {i0, i1, i2, i3, i4, i5, i6, i7, i8, i9};
uchar* CharBuffer = &auChars[0];
int n = 0;
for (int i = 1; i <= 3; i++){
putchar(CharBuffer[i]); // final output = 123
n += CharBuffer[i]; // I'm wanting to get this int to the value 123
}
puts("\n");
cout << n << endl; // output = 150 which I believe is the sum of the decimals 49 50 51
cin >> in;
}
I'm trying to get the integer 'n' to equal the numeric value one hundred and twenty three (123)
without much success.
I get the feeling it could be done with some sort of bitwise operation, but unfortunately
they confuse the hell out of me.
My hope is that someone might know of a library that exists to deal with this calculation
or offer some suggestions.
In any case, I appreciate all offered replies.
<edit>
I might add that my goal is efficiency over elegance :)