2020-06-28(C语言)八进制数转换为二进制数

//八进制数转换为二进制数

include

include

long long convertOctalToBinary(int octal);
int main()
{
int octal;
printf("输入一个八进制数:");
scanf("%d", &octal);
printf("八进制数%d转换为二进制数%lld。\n", octal, convertOctalToBinary(octal));
return 0;
}
long long convertOctalToBinary(int octal)
{
int remaider, decimal = 0, i = 0;
while (octal != 0)
{
remaider = octal % 10;
octal = octal / 10;
decimal = decimal + remaider * pow(8, i);
i++;
}
long long binary = 0;
int remaider1, j = 1;
while (decimal != 0)
{
remaider1 = decimal % 2;
decimal = decimal / 2;
binary = binary + remaider1 * j;
j = j * 10;
}
return binary;
}

你可能感兴趣的:(2020-06-28(C语言)八进制数转换为二进制数)