Search This Blog

Sunday, 15 September 2013

Binary to Decimal in C++

Digital Conversion from Binary 2 Decimal

#include<iostream.h>
#include<conio.h>

void main()
{

  char ch;
  do
  {
  int n,rem,sum=0,j=1;
  cout<<"\nEnter the binary value:";
  cin>>n;
  while(n>0)
  {
   rem=n%10;
   sum+=rem*j;
   j*=2;
   n=n/10;
  }
  cout<<"\nDecimal value is:"<<sum;
  cout<<"\nDo u want to continue:";
  cin>>ch;
 }while(ch!='0');
  getch();
}
output

No comments:

Popular Posts