8-12. (integer) Bit operation. write a program. After the user gives the start and end numbers, the following table is displayed, showing the decimal, binary, octal, and hexadecimal representation of all integers between the two numbers. if the character is printable ASCII, print it out. If none is printable, the header in the ASCII column is omitted.
#Filename:test8-12.pydef bitop(): elist=[] tlist=[] start=int(raw_input("Enter begin values:")) end=int(raw_input("Enter end values:")) promt="%-10s DEC %-9s BIN %-11s OCT %-8s HEX"%(' ',' ',' ',' ') flag=True if end < 33 or start > 126: falg=False else: promt+='%-8s ASCII'%(' ') #if flag: # print "%-10s DEC %-10s BIN %-10s OCT %-10s HEX %-10s ASCII"%(' ',' ',' ',' ',' ') #pass for v in range(start,end+1): elist=[str(v),bin(v),oct(v),hex(v)] if flag: if v in range(32,127): elist.append(chr(v)) else: pass tlist.append(elist) print promt for raw in tlist: #for x in raw: print "%-11s%s"%(' ',(10*' ').join(raw))
bitop()