Computer Science Canada Hexadecimal to Decimal |
Author: | pcmang [ Tue Jun 08, 2010 10:23 am ] |
Post subject: | Hexadecimal to Decimal |
I dont know how to create the processing/return method for this :S |
Author: | Insectoid [ Tue Jun 08, 2010 11:14 am ] |
Post subject: | RE:Hexadecimal to Decimal |
How would you do this on paper, mathematically? |
Author: | pcmang [ Tue Jun 08, 2010 2:56 pm ] |
Post subject: | Re: Hexadecimal to Decimal |
You dont know? Heres an example...not a good one tho. :S http://www.ehow.com/how_5059936_convert-hexadecimal-decimal.html |
Author: | Insectoid [ Tue Jun 08, 2010 3:07 pm ] |
Post subject: | RE:Hexadecimal to Decimal |
I do know, I was asking if you know. I'm assuming you do, so it's just a matter of turning that into code. The easiest way is to iterate over each element in the hex string (I'm assuming you're using a string for this) and search for that digit in a pre-defined array of elements 1-9, A-F (where each element is at the index corresponding to its decimal equivalent). There are much better ways of doing it that allow any base -> any base, but for hex -> dec only it's faster to just hard-code in the array. |