ID:195066
 
I'm actually surprised no one posted a hex2dec() function yet.
//Title: hex2dec
//Credit to: Popisfizzy
//Special thanks to: Lummox JR (showed me a way to
// slim it down more).

/*
Simple procedure to convert hexadecimal number into
decimal numbers. This takes 0 - 1, and A - F. If you
wish to allow for lowercase letters, simply pass the
arguments as uppertext(variable), or uncomment the
second line.
*/


proc/hex2dec(n)
// n = uppertext(n)
var/len = length(n)
for(var/a = 1, a <= len, a ++)
var/c = text2ascii(n, a)
. = . * 16 + (c - ((c < 58 && 48) || 55))

//Test code:

mob/verb/hex2dec_test(t as text)
world << "[t] (base 16) = [hex2dec(t)] (base 10)"
I've been sitting on one for a while, but it was too inefficient to post. I told myself, "Okay, you should fix this and then post it." But I tell myself a lot of things and they never seem to get done. ;-)
In response to Jtgibson
Jtgibson wrote:
But I tell myself a lot of things and they never seem to get done. ;-)

Of course. You're a programmer; that's the way we work.