# 二进制转十进制，八进制转十进制，十六进制转十进制，十进制转二进制，十进制转八进制，十进制转十六进制。

## - 二进制转十进制：

int BinarytoDecimal(long long n)
{
int decimalnumber = 0, i = 0, remainder;
while(n!=0)
{
remainder = n%10;
n/=10;
decimalnumber += remainder*pow(2,i);
i++;
}
return decimalnumber;
}


## - 八进制转十进制：

int OctaltoDecimal(long long n)
{
int decimalnumber = 0, i = 0, remainder;
while(n!=0)
{
remainder = n%10;
n/=10;
decimalnumber += remainder*pow(8,i);
i++;
}
return decimalnumber;
}


## - 十六进制转十进制：

int HexadecimaltoDecimal(char a[], int length)
{
int i, j;
int decimalnumber = 0;
for(i=length-1,j=0;i>=0;i--,j++)
{
if(isalpha(a[i]))
decimalnumber += (a[i]-'A'+10)*pow(16,j);
else
decimalnumber += (a[i]-'0')*pow(16,j);
}
return decimalnumber;
}


## - 十进制转二进制

int DecimaltoBinary(int n)
{
long binarynumber = 0;int i = 1, remainder;
while(n!=0)
{
remainder = n%2;
n /= 2;
binarynumber += remainder*i;
i *= 10;
}
return binarynumber;
}


int a[100];
int DecimaltoBinary(int n)
{

int i = 0, remainder;
while(n!=0)
{
remainder = n%2;
n /= 2;
a[i++] = remainder;
}
for(i=i-1;i>=0;i--)
printf("%d", a[i]);
}


## - 十进制转八进制

int DecimaltoOctal(int n)
{
int octalnumber = 0, i = 1;
while (n != 0)
{
octalnumber += (n % 8) * i;
n /= 8;
i *= 10;
}
return octalnumber;
}


## - 十进制转十六进制

#include <stdio.h>

char getnum(int a)
{
switch(a) //进制转换
{
case 0:
return '0';
break;
case 1:
return '1';
break;
case 2:
return '2';
break;
case 3:
return '3';
break;
case 4:
return '4';
break;
case 5:
return '5';
break;
case 6:
return '6';
break;
case 7:
return '7';
break;
case 8:
return '8';
break;
case 9:
return '9';
break;
case 10:
return 'A';
break;
case 11:
return 'B';
break;
case 12:
return 'C';
break;
case 13:
return 'D';
break;
case 14:
return 'E';
break;
case 15:
return 'F';
break;

}
}

int main()
{
int a[128];
int n,i=0;
scanf("%d",&n);

if(n==0)
{
printf("0");
}

else
{
while(n)
{
a[i++]=n%16;
n/=16;
}

for(i=i-1; i>=0; i--)
{
putchar(getnum(a[i]));
}
}
return 0;
}



02-01 9039
11-15 6万+
01-03 2912
06-17 2390
07-31 2370
04-19 2830
07-20 1万+
09-02 757
07-29 6575
05-14 2万+
03-21 4436
03-12 1万+
07-01 8万+
11-21 3549