#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int DectoHex(int decimal, unsigned char *hex, int length)
{
int i;
for (i = length - 1; i >= 0; i--)
{
hex[i] = (dec % 256) & 0xFF;
dec /= 256;
}
return 0;
}
int main()
{
register int i;
unsigned char tmpBuffer[12] = "";
unsigned long decimalToHexValue = 0;
scanf("%d", &decimalToHexValue);
//十进制转十六进制
DectoHex(decimalToHexValue , tmpBuffer, 4);
for (i = 0; i < 5; i++)
{
printf("tmpBuffer[%d] = 0x%02X\n", i, tmpBuffer[i]);
}
system("pause");
return 0;
}