|
发表于 2004-2-6 18:33:39
|
显示全部楼层
自己写了个程序试试,呵呵,只能转换int类型整数。
[php]
#include<stdio.h>
int main()
{
int num = 23165;
int temp[8];
int i;
/* print number in decimal base */
printf("the decimal number is %d\n", num);
/* transform binary number to hexadecimal notation */
for (i=7; i>=0; i--) {
if ( (temp = num & 0x0f) > 9)
temp += ('A' - 10);
else
temp += '0';
num = num >> 4;
}
/* print number in hexadecimal base */
printf("the hexadecimal number is ");
for (i=0; i<8; i++)
if ('0' != temp) printf("%c",temp);
printf("\n");
}
[/php] |
|