From 6c4e568cb2a7f9985658f43c622326e4da754daf Mon Sep 17 00:00:00 2001 From: Jeff Connelly Date: Sun, 3 Aug 2008 12:37:05 -0700 Subject: [PATCH] Base converter review: default to input and output base 10 and balanced 3 if not specified. --- tools/base_converter.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/base_converter.py b/tools/base_converter.py index 01136c0..0af43ed 100755 --- a/tools/base_converter.py +++ b/tools/base_converter.py @@ -276,15 +276,21 @@ if __name__ == "__main__": try: parts = line.split(",") - if len(parts) != 3: - print "Usage: value-to-convert,from-radix,to-radix" + if len(parts) == 1: + # Assume input is base 10, output is balanced 3 + val = parts[0] + frm = 10 + to = -3 + elif len(parts) != 3: + print "Usage: value-to-convert[,from-radix,to-radix]" print "Negative radixes indicate balanced." print "For example: 8,10,-3 to convert 8 to balanced trinary" + print "If ommitted, from-radix and to-radix default to 10 and -3" continue - - val, frm, to = parts - frm = int(frm) - to = int(to) + else: + val, frm, to = parts + frm = int(frm) + to = int(to) print base_convert(val, frm, to) except Exception, e: -- 2.11.4.GIT