4 Replies - 2684 Views - Last Post: 08 May 2012 - 09:20 AM Rate Topic: -----

#1 browngod2002   User is offline

  • New D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 27
  • Joined: 16-September 06

Converting Binary to Decimal

Posted 26 September 2006 - 05:19 PM

Description: inter in a binary number and the computer will show it decimal form.converts a binary number entered in by a user then displays its decimal form. Although the binary number is not really a binary number.
#include "stdafx.h"
#include <stdio.h>
#include <math.h>

/* function prototype */
int bintodec(int decimal);


int _tmain(int argc, _TCHAR* argv[])
{
     int decimal;

     printf("Enter an interger (0's and 1's): ");
     scanf_s("%d", &decimal);

     printf("The decimal equilavent is %d.n", bintodec(decimal));

     getchar();
     getchar();
     return 0;
}

int bintodec(int decimal)
{
     int total = 0;
     int power = 1;
     

     
     while(decimal > 0)
     {
          total += decimal % 10 * power;
          decimal = decimal / 10;
          power = power * 2;
          }

     return total;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Converting Binary to Decimal

#2 mariamalik   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-April 09

Re: Converting Binary to Decimal

Posted 15 May 2009 - 01:00 AM

It is a little bit lengthy. but it is easy to understand.
Was This Post Helpful? 0
  • +
  • -

#3 wakeupsiddhartha   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 02-August 10

Re: Converting Binary to Decimal

Posted 02 August 2010 - 05:39 AM

i wan"t to be a good programer
Was This Post Helpful? 0
  • +
  • -

#4 amit2011   User is offline

  • D.I.C Head

Reputation: -13
  • View blog
  • Posts: 64
  • Joined: 17-March 11

Re: Converting Binary to Decimal

Posted 11 June 2011 - 03:22 AM

gud programming... :) BUT HOW THI PROGRAM RUNS ITHOUT main()????? :-/
Was This Post Helpful? 0
  • +
  • -

#5 accfews   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 01-February 12

Re: Converting Binary to Decimal

Posted 08 May 2012 - 09:20 AM

amit2011 search _tmain does the job of main. http://msdn.microsof...=vs.100%29.aspx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1