Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can any one solve this question for me please, I don\'t knew even what a binary

ID: 3630838 • Letter: C

Question

Can any one solve this question for me please, I don't knew even what a binary is Write a program about printing the Decimal Equivalent of a binary input an integer containing only 0s and 1s ( a binary integer) and print its decimal equivalent .use the remainder and division operators to pick off the binary numbers digits one at a time from right to left .Just as in the decimal number system, in which the rightmost digit has a positional value of 1, and the next digit left has a positional value of 10, then 100, then 1000, and so on, in the binary number system the rightmost digit has a positional value of 1, the next digit left has a positional value of 2, then 4, then 8, and so on, thus the decimal number 234 can be interpreted as 4*1+3*10+2*100. The decimal equivalent of binary 1101 is 1*1+0*2+1*4+1*8 or 1+0+4+8 or 13

Explanation / Answer

please rate - thanks

#include <stdio.h>
#include <conio.h>
int main()
{int binary, val=1,decimal=0,digit;
printf("Enter a binary number: ");
scanf("%d",&binary);
printf("%d binary=",binary);
while(binary!=0)
   {digit=binary%10;
   binary/=10;
   decimal+=digit*val;
   val*=2;
   }
printf("%d decimal ",decimal);
getch();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote