//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)"
ID:195066
![]() Jun 21 2007, 5:37 pm (Edited on Jun 21 2007, 6:06 pm)
|
|
I'm actually surprised no one posted a hex2dec() function yet.
|
![]() Jun 22 2007, 2:34 pm
|
|
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. ;-)
|