OCTAL TO BINARY CONVERSION
Consider the following I/O samples.
SAMPLE INPUT : 23
SAMPLE OUTPUT: 10011
#include <stdio.h>
#include<math.h>
int main()
{
long int n, dec=0, bin=0, i=0;
scanf("%ld",&n);
while(n)
{
dec+=(n%10)*pow(8,i);
++i;
n/=10;
}
i=1;
while(dec)
{
bin+=(dec%2)*i;
dec/=2;
i*=10;
}
printf("%ld",bin);
return 0;
}
OUTPUT:
The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.
If you have any feedback about this article and want to improve this, please comment in the comment section.
C PROGRAM:
#include <stdio.h>
#include<math.h>
int main()
{
long int n, dec=0, bin=0, i=0;
scanf("%ld",&n);
while(n)
{
dec+=(n%10)*pow(8,i);
++i;
n/=10;
}
i=1;
while(dec)
{
bin+=(dec%2)*i;
dec/=2;
i*=10;
}
printf("%ld",bin);
return 0;
}
If you have any feedback about this article and want to improve this, please comment in the comment section.
Comments
Post a Comment