C Program - Binary to Decimal



#include <stdio.h>
#include <conio.h>

void main()
{
    int num, binary_val, decimal_val = 0, base = 1, rem;

    printf("Enter a binary number(1s and 0s) \n");
    scanf("%d", & num);
    binary_val = num;
    while (num > 0)
    {
        rem = num % 10;
        decimal_val = decimal_val + rem * base;
        num = num / 10 ;
        base = base * 2;
    }
    printf("The Binary number is = %d \n", binary_val);
    printf("Its decimal equivalent is = %d \n", decimal_val);
    getch();

}

Output
------------


Comments

Popular posts from this blog

Introduction to C++ Programming Language

The Assembly Process Of 8086 Microprocessor-Two Pass Assembling Steps

Installing 8086 Assembler on a Computer