10. Write a function decimalToBinary(n) that converts a positive decimal integer n to a string representing the corresponding binary number. Do the conversion by repeatedly dividing the number n by 2...


Can u solve it in Python thank you


10. Write a function decimalToBinary(n) that converts a positive decimal integer n to a string<br>representing the corresponding binary number. Do the conversion by repeatedly dividing the<br>number n by 2 using integer division, keepting track of the remainders, until the number is<br>reduced to 0. The remainders written in reverse order form the binary number string. The<br>following table (also shown in an earlier lab) illustrates the process.<br>N//2<br>N%2<br>2<br>1<br>2<br>1<br>1<br>1<br>0 (done)<br>Read upwards: 101 is 5<br>54<br>27<br>27<br>13<br>1<br>13<br>6<br>1<br>3<br>3<br>1<br>1<br>1<br>1<br>0 (done)<br>Read upwards: 110110 is 54<br>Do integer division of 5 by 2, so that N//2 is 2 with remainder 1. Now divide 2 by 2 to get 1<br>with remainder 0. Next divide 1 by 2 to get 0 with remainder 1. Concatenating the remainders<br>in reverse order makes 101, which is 5 in binary. Another example: N = 54. The division<br>sequence is 54, 27, 13, 6, 3, 1, 0; and the remainder sequence is 0, 1, 1, 0, 1, 1. The remainders<br>concatenated in reverse order produce: 110110, which is 54 in binary. Write a program which<br>converts the values from 0 to 9 to binary, using the decimalToBinary(n) function. The output<br>should look like:<br>O is the binary of 0<br>1 is the binary of 1<br>10 is the binary of 2<br>11 is the binary of 3<br>100 is the binary of 4<br>101 is the binary of 5<br>110 is the binary of 6<br>111 is the binary of 7<br>1000 is the binary of 8<br>1001 is the binary of 9<br>

Extracted text: 10. Write a function decimalToBinary(n) that converts a positive decimal integer n to a string representing the corresponding binary number. Do the conversion by repeatedly dividing the number n by 2 using integer division, keepting track of the remainders, until the number is reduced to 0. The remainders written in reverse order form the binary number string. The following table (also shown in an earlier lab) illustrates the process. N//2 N%2 2 1 2 1 1 1 0 (done) Read upwards: 101 is 5 54 27 27 13 1 13 6 1 3 3 1 1 1 1 0 (done) Read upwards: 110110 is 54 Do integer division of 5 by 2, so that N//2 is 2 with remainder 1. Now divide 2 by 2 to get 1 with remainder 0. Next divide 1 by 2 to get 0 with remainder 1. Concatenating the remainders in reverse order makes 101, which is 5 in binary. Another example: N = 54. The division sequence is 54, 27, 13, 6, 3, 1, 0; and the remainder sequence is 0, 1, 1, 0, 1, 1. The remainders concatenated in reverse order produce: 110110, which is 54 in binary. Write a program which converts the values from 0 to 9 to binary, using the decimalToBinary(n) function. The output should look like: O is the binary of 0 1 is the binary of 1 10 is the binary of 2 11 is the binary of 3 100 is the binary of 4 101 is the binary of 5 110 is the binary of 6 111 is the binary of 7 1000 is the binary of 8 1001 is the binary of 9

Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here