Tuesday 31 May 2016

Write a function that convert binary to decimal

#include <iostream.h>
#include<conio.h>
void main()
{
      clrscr();
      int a,b,c,f,g,d[32],e[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
      unsigned long int deci;
      char ch;
      cout<<"Enter binary number(maximum 32 digits):";
      c = 31;
      b = 0;
      while ((ch = getch()) != '\r')
      {
          d[b] = int(ch)-48;
          b++;
      }
      for(int w=(b-1); w>=0; w--)
      {
          e[c] = d[w];
          c--;
       }
       deci =0;
       g = 31;
       for(f=0; f<32; f++)
       {
           deci += (pow(2,g)*e[f]);
           g--;
       }
       cout<<"\n Decimal equivalent of binary number is : "<<deci;
       getch();
}

Share:

0 comments:

Post a Comment

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

About Me

My photo
A group of two, with a little hope of helping beginners to learn how to code :)
Powered by Blogger.

Comments

Facebook

Ad Home

Follow Us

Random Posts

Sponsor

Recent Posts

Header Ads

Popular Posts

Copyright © Functions in C++ | Powered by Blogger

Design by ThemePacific | Blogger Theme by NewBloggerThemes.com | Distributed By Blogger Templates20