Question: python 3.6 def binary(n): Given a n int n, convert it to binary. Hint: each time you divide a number by two, the remainder of

python 3.6

def binary(n):

Given a n int n, convert it to binary. Hint: each time you divide a number by two, the remainder of 1 or 0 is the rightmost bit in its binary representation; continually dividing by 2 , the remainders will give you more and more bits in its binary representation from right to left , until the

division itself (not the remainder) reaches zero and you're done.

Example: n is eleven. 11%2==1 , and 11//2==5. 5%2==1, and 5//2==2. 2%2==0. and 2//2==1. 1%2==1, and 1//2==0 (quotient is zero, so

we're done). In reverse, that gave us 1011(10112==2**3 + 2**1 + 2**0 == 8+3+1 == 1110).

Assume: n is a non-negative int

.Restriction: do not call int()

.Examples:binary(0)"0"

binary(5)"101"

binary(12)"1100"

binary(1030)"1000000110"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To convert a decimal number to its binary representation without using int we can utilize repeated d... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!