All pastes #913713 Raw Edit

Stuff

public python v1 · immutable
·published 2008-02-22 08:12 UTC
rendered paste body
def posbincon(userInput):	if userInput == 0: return 0	binaryString = ''	while userInput > 0:		j = userInput & 1		binaryString = str(j) + binaryString		userInput >>= 1	return binaryStringdef negbincon(userInput):	result = list(posbincon(0-userInput))	con = False	bit = len(result)	while bit > 0:		if con is False and result[bit-1] is '1': con = True		elif con is True:			if result[bit-1] is '0': result[bit-1] = '1'			elif result[bit-1] is '1': result[bit-1] = '0'		bit -= 1	result = '1'+string.join(result, '')	return resultprint "Welcome to the Ultimate, low budget binary to decimal converter"print "Now including Two's Complement"userInput = strwhile type(userInput) is not int:	userInput = raw_input("Enter the number here:> ")	try:		userInput = int(userInput)	except:		print "Input must be an integer."if userInput >= 0:	print "The binary value of %s is %s" %(userInput, posbincon(userInput))else:	print "The binary value of %s is %s" %(userInput, negbincon(userInput))