Right Click to Search

Saturday, February 6, 2025

Program to Convert Binary to Decimal number:Number System



Program to Convert Binary to Decimal number:Number System 

Note : 
As this program is for beginners (not for Experts) ,And  no Validations are Provided in Program . So Please Provide Correct Inputs ( 0 and 1 ) 
Logic of This Program :
  1. Accept Number from User ( Follow Upper Note)
  2. Divide Number by 10 and Store Remainder in variable rem
  3. Divide Original Number by 10 .
  4. sum = sum + rem * pow(2,power);  // First Iteration power=0 then Power is Incremented in each Iteration
  5. Calculate sum
  6. Display Sum as Decimal Representation of Given Binary
Program :
#include<stdio.h>
#include<conio.h>
#include<math.h>
void bin_dec(long int num)   // Function Definition
{
long int rem,sum=0,power=0;
while(num>0)
 {
 rem = num%10;
 num = num/10;
 sum = sum + rem * pow(2,power);
 power++;
 }
printf("Decimal number : %d ",sum);
}
//-------------------------------------
void main()
{
long int num;
clrscr();
printf("Enter the Binary number (0 and 1): ");
scanf("%ld",&num);
bin_dec(num);
getch();
}
Output :
Enter the Binary number : 111
Decimal number : 7

Tags / Keywords : | ,

Stumble
Delicious
Technorati
Twitter
Facebook

1 Comment:

Anonymous said...

Very Simple Program ,

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates