This is a program to convert binary to decimal
/* author- WYES KARNY */
#include<stdio.h>
int main()
{
int a,rem,des=0,i=1;
printf("Enter a binary number ");
scanf("%d",&a);
while(1)
{
rem=a%10;
a=a/10;
des+=rem*i;
i=i*2;
if(a==0)
break;
}
printf("\nThe equevalent desimal value is %d \n",des);
return 0;
}
And for the Decimal to binary
#include<stdio.h>
int main()
{
int a,i,shift,bit;
scanf("%d",&a);
for(i=0;i<16;i++)
{
shift=a<<i;
shift=shift>>15;
bit=shift&1;
if(bit==1)
printf("1");
else
printf("0");
}
}
0 comments:
Post a Comment