Thursday, 26 October 2017

Binary to Decimal

#include<stdio.h>
int main(int argc, char * argv[])
{
    int  num, binary_val, decimal_val = 0, base = 1, rem;
    if(argc!=2)
    {
        exit(1);
    }
    num = atoi(argv[1]);
    binary_val = num;
    while (num > 0)
    {
        rem = num % 10;
        decimal_val = decimal_val + rem * base;
        num = num / 10 ;
        base = base * 2;
    }
    printf("Binary number = %d \n", binary_val);
    printf("Its equivalent decimal no = %d \n", decimal_val);
    return 0;
}

No comments:

Post a Comment

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...