C programme to convert decimal to binary & vice- versa

C programme to convert decimal to binary & vice- versa


Link to Turbo C: HERE 

/* Decimal to binary */
#include<stdio.h>
#include<conio.h>
void main()
{
int x,i,rev=0,num;
clrscr();
printf("Enter number in decimal:\n");
scanf("%d",&num);
for(i=num;i>0;i=i/2)
{
x=i%10;
rev=rev+x;
}
printf("\nBinary is: %d",rev);
getch();


}

/* To convert Binary to decimal */

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
long int x,sum=0,power=0,num;
clrscr();
printf("Enter number in Binary:\n");
scanf("%ld",&num);
while(num>0)
{
x=num%10;
num=num/10;
sum=sum+x*pow(2,power);
power++;
}
printf("\nDecimal is: %ld",sum);
getch();
}
SHARE

Ramandeep Singh

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

2 $type={blogger}:

  1. This post is good enough to make somebody understand this amazing thing, and I’m sure everyone will appreciate this interesting things. Hex To Decimal

    ReplyDelete
  2. I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. hex to decimal conversion

    ReplyDelete