Computer Science, asked by aryansharma91, 4 months ago

Sumit is converting a decimal number to a binary number . he needs to calculate the remainder in each step. which of operator do you suggest him to use for this task?

Answer=


value based question from Python chapter class 7 ​

Answers

Answered by sriram25807
8

Explanation:

The way I showed him was to repeatedly divide the number by 2 and then take the remainder, the binary number will be the remainders read from bottom to top.

ex: Convert 22 to a binary representation 22 / 2 = 11 R 0 11 / 2 = 5 R 1 5 / 2 = 2 R 1 2 / 2 = 1 R 0 1 / 2 = 0 R 1 answer = 10110

After I showed him the algorithm and an example, he set off to do the rest of his problems. Today he sent me an email and asked me why this method works. I was sort of shocked by that question, I have never given a second thought to why this works, I only did as I was told knowing that if I performed this algorithm I would always get the right answer in binary.

I thought about it for awhile and still can't seem to figure out WHY this method works, any help would be appreciated. This isn't for an assignment, merely my curiosity and frustration at not asking this question before.

Thanks

Edit

Do you mind explaining how you went from:

n=e0×20+e1×21+⋯+ek×2kn=e0×20+e1×21+⋯+ek×2k

to

n=e0+2(e1+e2×2+⋯+ek×2k−1),n=e0+2(e1+e2×2+⋯+ek×2k−1),

I am not following the transition to the closed form.

Answered by vijayenterprises260
0

Answe%(Remainder)operator

Explanation:

Similar questions