int DEC_HEX(uint32_t Dec)
{
int ram = 0;//整
int ray = 0;//余
uint32_t Hex = 0x0;
int i =0;
do{
ram = Dec /16;
ray = Dec %16;
Dec = ram;
switch(ray) //看余数为多少
{
case 0:
{
Hex |= (0x0<<(i*4)); //然后右移四位,让下一个四位在下一个循环进行运算
break;
}
case 1:
{
Hex |= (0x1<<(i*4));
break;
}
case 2:
{
Hex |= (0x2<<(i*4));
break;
}
case 3:
{
Hex |= (0x3<<(i*4));
break;
}
case 4:
{
Hex |= (0x4<<(i*4));
break;
}
case 5:
{
Hex |= (0x5<<(i*4));
break;
}
case 6:
{
Hex |= (0x6<<(i*4));
break;
}
case 7:
{
Hex |= (0x7<<(i*4));
break;
}
case 8:
{
Hex |= (0x8<<(i*4));
break;
}
case 9:
{
Hex |= (0x9<<(i*4));
break;
}
case 10:
{
Hex |= (0xA<<(i*4));
break;
}
case 11:
{
Hex |= (0xb<<(i*4));
break;
}
case 12:
{
Hex |= (0xC<<(i*4));
break;
}
case 13:
{
Hex |= (0xd<<(i*4));
break;
}
case 14:
{
Hex |= (0xe<<(i*4));
break;
}
case 15:
{
Hex |= (0xf<<(i*4));
break;
}
}
Hex &= 0xFFFFFFFF;
i++;
} while
(ram/16 >= 0 && i <= 8);
return Hex;
}
用这种转换方式可以转换8位的十进制数据,想要转换更多位的话把i的值更改即可,解决网上都是转换输入值的问题。