mazurov
9/18/2014 - 6:00 PM

5.7 Base conversion

5.7 Base conversion

# 5.7 Base conversion


def base10(s, b):
	res = 0;
	for c in s:
		res = res * b + (ord(c)-ord('0') if ord(c) <= ord('9') else 10 + ord(c) - ord('A'))
	return res

x = base10('AA',16)
print(x)
x = base10('111',2)
print(x)