"""
Bitwise approach using powers of 2
"""

# Import required functions for mathematical operations.
from math import log2, floor

# Prompt the user to input a decimal number as an integer.
decimal = int(input("Please enter the decimal representation of a number: "))

# Compute the number of bits required to represent the decimal number in binary.
# This is equivalent to the floor of log2(decimal) + 1.
# Alternatively, you can use int.bit_length() for this purpose.
l = floor(log2(decimal)) + 1

# Initialize an empty string to store the binary result.
result = ""

# Loop through each bit position, from the most significant to the least significant.
for i in range(l):
    # Calculate the value of the current power of 2 (2^(l-i-1)).
    power = 2**(l - i - 1)
    # Determine whether the current bit is 1 or 0 by dividing the decimal number by the power.
    bit = decimal // power
    # Subtract the value of the current bit from the decimal number.
    decimal -= bit * power
    # Append the current bit to the binary result.
    result += str(bit)

# Print the final binary representation of the input number.
print(f"The binary representation of your number is {result}")
