大家好,帮帮忙,在单片机中想把十进制X = 123456 转为十六进制 X = 0x123456的格式,有什么方法吗,或者有代码例子吗?谢谢!
------解决方案--------------------
long DecimalToHex(long iVal)
{
unsigned long iRet=0;
long i=10;
while( i<iVal ) i*=10;
i /= 10;
while(iVal)
{
iRet <<= 4;
iRet
------解决方案--------------------
= (iVal/i) & 0x0F;
iVal = iVal%i;
i /= 10;
}
return iRet;
}