# I'm trying to put c code together to convert up to a 5 digit binary to decimal . I keep getting wrong answers : here's my c code so far . Can you please explain throughly as I am a begginer .   #include <stdio.h> int main() {   int a1, b1, c1, d1, e1, n1, decimal;   printf( "Enter a five-digit integer in 1's and 0's\n" );   scanf("%d", &n1 );   a1= n1 % 10;   b1= n1 / 10 % 10;   c1= n1 / 100 % 10;   d1= n1 / 1000 % 10;   e1= n1 / 10000;   decimal = a1 + b1 + c1 + d1 + e1;   printf("\nThe decimal equivalent of given binary number %d is: %d\n", n1,decimal);   return 0; }

Question
26 views

I'm trying to put c code together to convert up to a 5 digit binary to decimal . I keep getting wrong answers : here's my c code so far . Can you please explain throughly as I am a begginer .

#include <stdio.h>

int main()

{

int a1, b1, c1, d1, e1, n1, decimal;

printf( "Enter a five-digit integer in 1's and 0's\n" );

scanf("%d", &n1 );

a1= n1 % 10;

b1= n1 / 10 % 10;

c1= n1 / 100 % 10;

d1= n1 / 1000 % 10;

e1= n1 / 10000;

decimal = a1 + b1 + c1 + d1 + e1;

printf("\nThe decimal equivalent of given binary number %d is: %d\n", n1,decimal);

return 0;

}

check_circle

Step 1

Programming instruction:

To obtain the decimal equivalent of a given binary number, extract the digits of binary number beginning from the rightmost digits and keep a variable DecValue. While extracting the digits from binary number, multiply the digit with the base (power of 2) and add it to the DecValue variable. In the end, the DecValue will store the required decimal value.

Step 2

Program:

#include <math.h>

#include <stdio.h>

int DecimalToBinary(long long n);

int main() {

long long n;

printf("Enter a binary number: "); //Enter binary number

scanf("%lld", &n);

printf("%lld in binary = %d in decimal", n, DecimalToBinary(n));

return 0;

}

int DecimalToBinary(long long n) {  //Function to covert the binary number into decimal

&...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in