pythonの基数変換において、2, 8, 16進数なら…
format() , int()が利用できるので…
#!/usr/local/bin/python # -*- coding: utf-8 -*- def main(): from_int() to_int() def from_int(): org_int = 10 for base in ["b","o","x","X"]: from_int = format(org_int,base) print base +":"+str(org_int) +"->"+ str(from_int) print '' def to_int(): for org_str, base in {"1010":2, "12":8, "a":16}.items(): print str(base)+":"+ org_str +"->"+ str( int(org_str, base) ) if __name__ == '__main__': main()
↑こう書くと↓こう実行できます
$ ./foo.py b:10->1010 o:10->12 x:10->a X:10->A 16:a->10 8:12->10 2:1010->10
2, 8, 16進数以外の基数変換であれば
Math::BaseCalc for perlのcloneを書く必要があるのかな? http://search.cpan.org/perldoc?Math%3A%3ABaseCalc