10进制转换成16进制的函数(自写函数模板)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
void change(int n, char * Num16) //10转换成16进制,Num16保存处理后的16进制数 { Num16[0] = '\0'; int a, i = 0; do { a = n % 16; n = n / 16; if(a > 9) Num16[i] = a - 10 + 'A'; else Num16[i] = a + '0'; i++; }while(n); Num16[i] = '\0'; for(int j = 0; j < i/2; j++) //前后逆置 { char c; c = Num16[j]; Num16[j] = Num16[i-j-1]; Num16[i-j-1] = c; } }
其中,函数中n是转换前的十进制数,Num16保存的是转换后的十六进制的数
更加方便的:
C++中:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
int a,b,c; cin>>a>>b>>c; cout<<hex<<a<<b<<c<<endl;
一道又一道,好高兴!