Quote:
Originally Posted by Ensky
he want's to convert hex to decimal, not decimal to hex :-)
|
ups sorry, my fault.
-Get the last digit of the hex number, call this digit the currentDigit.
-Make a variable, let's call it power. Set the value to 0.
-Multiply the current digit with (16^power), store the result.
-Increment power by 1.
-Set the the currentDigit to the previous digit of the hex number.
-Repeat from step 3 until all digits have been multiplied.
-Sum the result of step 3 to get the answer number.
Example:
Convert the number 35432 HEXADECIMAL to DECIMAL
2x(16^0) + 3x(16^1) + 4x(16^2) + 5x(16^3) + 3x(16^4) =
2 + 3x16 + 4*256 + 5*4096 + 3*65536 =
2 + 48 + 1024 + 20480 + 196608 =
218162