将非常长的int值转换为Hex [英] Convert a very long int value To Hex

查看:57
本文介绍了将非常长的int值转换为Hex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个非常长的整数值,如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

推荐答案

Ahmad Jalil Qarshi写道:
Ahmad Jalil Qarshi wrote:




我有一个非常长的整数值,如9987967441778573855.

现在我想要将它转换为等效的十六进制值。


结果必须是8A9C63784361021F


我使用过sprintf(pHex,%0X,9987967441778573855)。但它只有

返回8

十六进制值。


请注意我在Unix上使用纯C语言。


感谢您的预期,
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,



尝试%Lx或%llx或%llx格式说明符。

Try the "%Lx" or "%llx" format specifier.


8月27日晚上9:05,santosh< santosh .... @ gmail.comwrote:
On Aug 27, 9:05 pm, santosh <santosh....@gmail.comwrote:

Ahmad Jalil Qarshi写道:
Ahmad Jalil Qarshi wrote:


Hi,


I有一个非常长的整数值,如998796744563877.

现在我想要将它转换为等效的十六进制值。
I have an integer value which is very long like 998796744563877.
Now I
want to convert it into equivalent Hex value.


结果必须是8A9C63784361021F
The result must be 8A9C63784361021F


我用过sprintf( PHEX,"%0X",998796744563877)。但它只有

返回8

十六进制值。
I have used sprintf(pHex,"%0X",998796744563877). But it only
returns 8
Hex values.


请注意,我在Unix上使用纯C。
Kindly note that I am using pure C on Unix.


在预期中感谢,
Thanks in anticipation,



尝试%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


Ahmad Jalil Qarshi写道:
Ahmad Jalil Qarshi wrote:

8月27日晚上9:05 ,santosh< santosh .... @ gmail.comwrote:
On Aug 27, 9:05 pm, santosh <santosh....@gmail.comwrote:

> Ahmad Jalil Qarshi写道:
>Ahmad Jalil Qarshi wrote:


Hi,


我有一个非常长的整数值,如998796744563877.

现在我

想要将其转换为等效的十六进制值。
I have an integer value which is very long like 998796744563877.
Now I
want to convert it into equivalent Hex value.


结果必须是8A9C63784361021F
The result must be 8A9C63784361021F


我用过sprintf( PHEX,"%0X",998796744563877)。但它只有

返回8

十六进制值。
I have used sprintf(pHex,"%0X",998796744563877). But it only
returns 8
Hex values.


请注意,我在Unix上使用纯C。
Kindly note that I am using pure C on Unix.


在预期中感谢,
Thanks in anticipation,


尝试%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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆