问题描述
我有一个非常长的整数值,如9987967441778573855.
现在我
想转换它变成等效的十六进制值。
结果必须是8A9C63784361021F
我使用过sprintf(pHex,%0X,9987967441778573855) 。但它只有
返回8
十六进制值。
请注意我在Unix上使用纯C语言。
感谢您的期待,
问候,
Ahmad Jalil Qarshi
Hi,
I have an integer value which is very long like 9987967441778573855.
Now I
want to convert it into equivalent Hex value.
The result must be 8A9C63784361021F
I have used sprintf(pHex,"%0X",9987967441778573855). But it only
returns 8
Hex values.
Kindly note that I am using pure C on Unix.
Thanks in anticipation,
Regards,
Ahmad Jalil Qarshi
推荐答案
尝试%Lx或%llx或%llx格式说明符。
Try the "%Lx" or "%llx" format specifier.
尝试%Lx或%llx或%llx格式说明符。
Try the "%Lx" or "%llx" format specifier.
亲爱的Santosh,
我使用了%Lx并返回7d299ca5
当我使用%llx时它返回7d299ca50000f0b2这不是十六进制为
998796744563877.它必须返回38C667D299CA5。
问候,
Ahmad Jalil Qarshi
Dear Santosh,
I have used "%Lx" and it returned 7d299ca5
When I used "%llx" it returned 7d299ca50000f0b2 which is not Hex for
998796744563877. It must return 38C667D299CA5.
Regards,
Ahmad Jalil Qarshi
尝试%Lx"或%llx或%llx格式说明符。
Try the "%Lx" or "%llx" format specifier.
亲爱的Santosh,
我使用了%Lx并返回7d299ca5
当我使用%llx时它返回7d299ca50000f0b2,这不是十六进制为
998796744563877.它必须返回38C667D299CA5。
Dear Santosh,
I have used "%Lx" and it returned 7d299ca5
When I used "%llx" it returned 7d299ca50000f0b2 which is not Hex for
998796744563877. It must return 38C667D299CA5.
确保您在C99符合模式下进行编译。这样做的细节
将根据您的编译器而有所不同。对于gcc传递''std = c99''
命令行开关。
确保使用long long类型的对象或' 'unsigned long long''
存储价值。
确保您的标准库支持C99和长期
类型。像Microsoft的默认CRT这样的一些破坏的库没有这样的支持。
以下程序在我的系统上工作正常并打印出预期的
值。将它与你所写的相比较。
#include< stdio.h>
int main(void)
{
long long val = 998796744563877ll;
printf("%lld in hex is:%llx \ n",val,val);
返回0;
}
Ensure that you are compiling in C99 conforming mode. The details to do that
will vary according to your compiler. For gcc pass the ''std=c99''
commandline switch.
Ensure that you use an object of type ''long long'' or ''unsigned long long'' to
store the value.
Ensure that your Standard library has support for C99 and the long long
type. Some broken libraries like Microsoft''s default CRT do not have such
support.
The following program works fine on my system and prints the expected
values. Compare it with what you''ve written.
#include <stdio.h>
int main(void)
{
long long val = 998796744563877ll;
printf("%lld in hex is: %llx\n", val, val);
return 0;
}
这篇关于将非常长的int值转换为Hex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!