Use while loop to convert from Python Decimal to binary

Asked 2 years ago, Updated 2 years ago, 126 views

For example, to convert the number 92 to binary:

92 / 2 - quotient = 46 remainder = 0

46 / 2 - quotient = 23 remainder = 0

23 / 2 - quotient = 11 remainder = 1

11 / 2 - quotient = 5 remainder = 1

5 / 2 - quotient = 2 remainder = 1

2 / 2 - quotient = 1 remainder = 0

1 / 2 - quotient = 0 remainder = 1

I want to get results like this No matter how much I googled, I only use divmod or other methods, so I'm asking here. I don't use break and continue!

python while-loop

2022-09-20 16:39

1 Answers

What is sharing? Finds how many times you can subtract the divisor from the divisor.

Implement the task of infinitely subtracting the divisor from the divisor.


2022-09-20 16:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.