Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def pad(x, count): ##Adds leading 0s to the start of the string to match the count given
- while len(x) < count:
- x = ("0%s"%x)
- return x
- def bit_count(x): ##returns a standard binary count number (1, 2, 4, 8, 16, 32, 64 etc...)
- bits = 1;
- while bits < len(x):
- bits = bits*2
- return bits
- def bin_to_int(x): ##converts binary string to int
- return int(x, 2)
- byte = "{0:b}".format(int(raw_input("Enter Number:"))) ##converts int input into binary string
- print("This is a %s bit number." %bit_count(byte))
- print(pad(byte, bit_count(byte)))
- print(bin_to_int(byte))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement