Pages

Saturday, May 19, 2012

Program to convert Binary Number to Decimal


Computer only understand two numbers, they are 1 and 0 called binary number. Decimal means number 0,1,2,3,4,5,6,7,8,9. You have to convert binary number to decimal number.
//binary to decimal conversion.
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
int bin,dec=0,i=0,dig;
printf(“\n Enter a binary no.:”);
scanf(“%d”,&bin);
while(bin>0)
{
dig=bin%10;
dec=dec+pow(2,i++)*dig;
bin=bin/10;
}
printf(“\n Decimal conversion of given no.: %d”,dec);
}

Input11011
Output27
Using this procedure you can also convert octal to decimal and hexadecimal to decimal by changing the base to 8 or 16 respectively.

2 comments:

  1. Quality posts is the crucial to interest the viewers to
    go to see the web page, that's what this web page is providing.

    My page; this is great
    Also visit my website : great point

    ReplyDelete
  2. I quite like reading an article that can make people think. Also, thanks for allowing for me to comment! hex to decimal converter

    ReplyDelete