//Title: bin2dec
//Credit to: Popisfizzy
/*
Simple procedure to convert binary into decimal.
*Note: This version will only work on 16-bit
strings or less.
*/
proc/bin2dec(n)
var/len = length(n)
. = 0
for(var/a = len, a > 0, a --)
. += (text2ascii(n, a) == 49 && (1 << (len - a)))
//Test Code:
mob/verb/bin2dec_test(n as text)
world << "[n] (base 2) = [bin2dec(n)] (base 10)"
ID:195064
Jun 21 2007, 6:08 pm (Edited on Jul 15 2007, 8:49 pm)
|
|