How to do a number input by user first then only display the answer?
a = int(raw_input("Enter number: "),twoscomp)
def tobin(x, count = 8):
return "".join(map(lambda y:str((x>>y)&1), range(count-1, -1, -1)))
def twoscomp(bin_str):
return tobin(-int(bin_str,2),len(bin_str))
print a
I believe this is what you're trying to do?
def tobin(x, count = 8):
return "".join(map(lambda y:str((x>>y)&1), range(count-1, -1, -1)))
def twoscomp(bin_str):
return tobin(-int(bin_str,2),len(bin_str))
a = twoscomp(raw_input("Enter number: "))
print a
Things to note:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.