 # A Program Convert Binary to Decimal Number ] Email
 Submitted on: 1/8/2015 3:55:00 PM By: Cool_Gemini (from psc cd) Level: Beginner User Rating:    By 2 Users Compatibility: C, C++ (general), UNIX C++ Views: 6020

Write a program to convert binary number to decimal number.

code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 ``` //************************************** // Name: A Program Convert Binary to Decimal Number ] // Description:Write a program to convert binary number to decimal number. // By: Cool_Gemini (from psc cd) //************************************** #include #include #include int main(void) { int i=0,j=0,sum=0,n,tmp,tmp1; long int arr; char pch; clrscr(); printf("Enter binary number : "); while (scanf("%d",&n) != 1) { while ((pch = getchar()) != '\n') putchar(pch); // dispose of bad input printf(" is not an binary number.\nPlease enter a "); printf("binary value, such as 100, 1011, or 1111: "); } while(n!=0) { arr[i]=n%10; n=(n-arr[i])/10; tmp=i; i++; } if(i>=5) { printf("\n\tNumber Out Of Range"); getch(); exit(0); } for(j=0;j<=tmp;j++) if(arr[j]!=1&&arr[j]!=0) { printf("Enter binary no. only"); getch(); exit(0); } tmp1=tmp; for(j=0;j<=tmp;j++) { sum=sum+(arr[j]*(pow(2,tmp1))); tmp1--; } printf("\nEquivalent decimal number is %d",sum); getch(); return 0; }```

Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...) 9/2/2015 3:17:31 PMjenny

Converts Decimal Numbers to Binary

#include
#include
void main()

{

int i, ch;
cout<<"Enter an integer: ";
cin>>ch;
for(i=0x80;i;i=i>>1)
cout<<((ch&i)?'1':'0');

getch();

cout< }
Converts Decimal Numbers to Binary

#include
#include
void main()

{

int i, ch;
cout<<"Enter an integer: ";
cin>>ch;
for(i=0x80;i;i=i>>1)
cout<<((ch&i)?'1':'0');

getch();

cout< }
http://cplusplus.happycodings.com/beginners-lab-assignments/code41.html
(If this comment was disrespectful, please report it.)