DEV Community

Discussion on: Daily Challenge #255 - Is There an Odd Bit?

Collapse
 
peter279k profile image
peter279k

Here is my solution with Python:

def any_odd(x):
    print(x)
    bin_string = ""

    num = x
    while num != 0:
        bit = num % 2
        num = int(num / 2)

        bin_string = str(bit) + bin_string

    index = len(bin_string) - 1

    for bit in bin_string:
        if index % 2 == 1 and bit == '1':
            return 1
        index -= 1

    return 0