What would be the easiest way of going about converting a 3 digit hexadecimal number to decimal, I think that a switch statement is out of the question due to multiple digits. Would it be easiest just to assign A - F numerical values and just do the arithmetic?
And just to clarify, all of the hexadecimals are base 16.
And can somebody please clarify what the value of 3A7 is? My impression is that it is (3 * 1) + (10 * 16) + (7 * 1) = 170 ?
Now that i've got the arithmetic part, what would be the easiest way to write this in C++?
Develop your algorithm for an 'any case' scenario. This is usually done by doing 3 or 4 by hand and figuring out how to abstract it for every case. That will give you an algorithm, which you can change into pseudocode, which you can then code.
If you are as lazy as me, google for "C++ hex to dec convert"
and you would see this:
http://www.daniweb.com/code/snippet470.html
A typical answer with good sample code.
Actually for the algorithm, I would try this(In ANSI C, this is my concern):
First, put user input into an char array.
Second, use a loop to:
read array[i].
do the math convert from hex to dec //switch cases where char == 'A', ...
store the result into dec[i] //an int array
When you finish the loop, you should get the fully int array dec[]
Then you use another loop to work out the result
Return it to the user.
This is the newbie's approach, so just fundamental data types and basic knowledges are used.