Python Day 10: Binary Numbers



Given a base-10 integer,n , convert it to binary (base-2). Then find and print the base-10 integer denoting the maximum number of consecutive 1's in n's binary representation.



  1. import math
  2. import os
  3. import random
  4. import re
  5. import sys
  6. if __name__ == '__main__':
  7. n = int(input())
  8. numbers = str(bin(n)[2:]).split('0')
  9. lenghts = [len(num) for num in numbers]
  10. print(max(lenghts))