Computer Science, asked by arnav9688, 3 months ago

1. Write a program to Input a number and print its binary equivalent. For eg ( the binary equivalent of 6 is 110).

To find the binary number keep dividing the number by 2 till you get a 0 in the end.

Division Remainder (R)

28 / 2 = 14 0

14 / 2 = 7 0

7 / 2 = 3 1

3 / 2 = 1 1

1 / 2 = 0 1

Write the remainder from bottom to top 11100 is the binary equivalent of 28.​

Answers

Answered by allysia
77

Answer:

Using python (consider the attachment if latex not understandable):

\\\tt n=int(in put("Enter\ a\ number: ")) \\\tt a=[] \\\tt while\ n>0\ and\ n<(n+1): \\\tt {\qquad    rem=n\%2 } \\\tt{\qquad    n //=2 } \\\tt {\qquad    a.append(rem) } \\\tt bin=0 \\\tt for\ i\ in\ range(0,len(a)): \\\tt{\qquad    bin+=(10**i)*(a[i]) } \\\tt print(bin)

Attachments:
Similar questions