This topic has been archived. It cannot be replied.
-
工作学习 / 学科技术讨论 / 老革命遇到新问题:int 转换成 HEX string例如:124 的hex 表示为 00 7C,那位高人可以帮我把它转换成HEX sting “007C" 最好用C语言。。。
给您先鞠躬了。。。。:))))
-serenade123(橘子红了);
2007-11-5
{120}
(#4038026@0)
-
Check the URL http://einaros.blogspot.com/2006/11/put-hex-on-that-dump.html
-deep_blue(BLUE);
2007-11-5
(#4038054@0)
-
sprintf(szBuf, "%02X%02X", int%256, int/256);
-johnnyzh(bubble);
2007-11-5
(#4038092@0)
-
Use sprintf (string, "%04X", int)
-bugkiller(Driver Coding);
2007-11-5
(#4038096@0)
-
谢谢-deep_blue(BLUE),johnnyzh(bubble) and bugkiller(Driver Coding)。。。我可能没有说明白。。。是写一个小程序实现这个功能,不能用sprintf.
因为我要用另外一种语言重写。。。那中语言不支持ANSI C的sprintf()...所以,请大家再想一想。。。谢谢。。。
-serenade123(橘子红了);
2007-11-5
{150}
(#4038478@0)
-
那就自己递归吧
-bugkiller(Driver Coding);
2007-11-5
(#4038494@0)
-
itoa(i, str, 16) 是标准库的函数,如果也没有的话,用i%16, 余数就是每一个16进制的数字。i = n;
hex[]={'1', '2', ... 'F'};
while ( i > 0 ) {
p[] = hex[i%16];
i/=16;
}
return reverse(p);
-canadiantire(轮胎-Liberate TuteMa);
2007-11-5
{114}
(#4038495@0)
-
多谢轮胎...简单易懂:))))
-serenade123(橘子红了);
2007-11-5
(#4039572@0)
-
A recursive function of modulus for it is not difficult.
-deep_blue(BLUE);
2007-11-5
(#4038576@0)
-
那也不是很复杂。一个loop不就行了?
char* pStr;
int num;
for(int i = 0; i < 8; i ++)
{
int temp = (num & 0xf0000000)>>28;
if ( temp >= 0 && temp <= 9 )
*pStr++ = '0' + temp;
else
*pStr++ = 'A'+temp-10;
num<<=4;
}
*pStr = '\0';
大概就这个样子
-baalinca(scarb);
2007-11-5
{249}
(#4038587@0)
-
你的程序让我有点乱....:))))请解释一下....我也比较笨...没办法...:)))
-serenade123(橘子红了);
2007-11-5
{26}
(#4039587@0)
-
int是32位,4bits一组,用位操作,从左往右,0-9对应asicii码'0'-'9';10-15对应'A'-'F'。
-baalinca(scarb);
2007-11-6
(#4040425@0)
-
俺的系统中....int 是16bit的
-serenade123(橘子红了);
2007-11-7
(#4044665@0)
-
这是什么意思...(num & 0xf0000000)>>28 ?
-serenade123(橘子红了);
2007-11-7
(#4044658@0)
-
这是取最高4bits的值
-baalinca(scarb);
2007-11-8
(#4045704@0)
-
俺是这样实现的....不知道在其他系统中是否可行?string result[0:1];
int .num; //num will be conerted to Hex string
string .num^s = @num '<<' 1;
result ':=' num^s for 2;
注:俺的系统中,int 为16位
-serenade123(橘子红了);
2007-11-7
{163}
(#4044718@0)
-
This code might be easier to understand.
-deep_blue(BLUE);
2007-11-8
{844}
(#4045305@0)