C Programming

Binary to Decimal

Learn C programming for convert binary number to decimal number

6/3/2018
0 views
binary-to-decimal.cC
#include<stdio.h>

int main() {
	int decimal = 0, binary, i = 1, reminder;
	printf("Welcome to Binary to Decimal converter\n");
	printf("Enter a binary number:\n");
	scanf("%d",&binary);
	while(binary != 0) {
		reminder = binary % 10;
		decimal += reminder * i;
		i *= 2;
		binary /= 10;
	}
	printf("Decimal value is: %d\n",decimal);
	return 0;
}


/* Output */
Welcome to Binary to Decimal converter
Enter a binary number:
1000

Decimal value is: 8
C languageC programmingbinary to decimal conversationbinary to decimal converter

Related Examples