Skip to content

Commit

Permalink
Create binarytodecimalconverter.c
Browse files Browse the repository at this point in the history
added program to convert a 5 digit binary number to decimal
  • Loading branch information
gormleymark authored Oct 24, 2018
1 parent 2bf5215 commit 715be1b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions binarytodecimalconverter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// binary to decimal converter
// limited to binary with 5 digits

#include <stdio.h>

int main()
{
int a, b, d1, d2, d3, d4, d5;
printf("Enter a 5 digit binary number: \n");
scanf_s("%d", &a);
d1 = a / 10000;
d2 = a / 1000;
d2 = d2 % 10;
d3 = a / 100;
d3 = d3 % 10;
d4 = a / 10;
d4 = d4 % 10;
d5 = a % 10;

b = d1 * 16 + d2 * 8 + d3 * 4 + d4 * 2 + d5 * 1;

printf("%d in binary is %d in decimal\n", a, b);
}

0 comments on commit 715be1b

Please sign in to comment.