Hexadecimal to Decimal
Author |
Message |
pcmang
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Tue Jun 08, 2010 11:14 am Post subject: RE:Hexadecimal to Decimal |
|
|
How would you do this on paper, mathematically? |
|
|
|
|
![](images/spacer.gif) |
pcmang
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
|
|