DEV Community

DAY 10: BINARY NUMBERS

M__ on June 20, 2020

Binary numbers represent a value in form of 1’s and 0’s. Python has a bin() method for converting integers to their binary format which makes the e...
Collapse
 
udkumar profile image
uday kumar
n = int(input())
max_one_count = 0
one_count = 0

while n != 0:
    factor = n // 2
    remainder = n - 2 * factor
    n = factor
    if remainder == 1:
        one_count += 1
        max_one_count = max(max_one_count, one_count)
    else:
        one_count = 0

print(max_one_count)
Collapse
 
idimaimuna profile image
M__

Thank you so much.