简体   繁体   English

ISO C99 intypes.h:printf不为uint64_t打印十六进制值

[英]ISO C99 intypes.h: printf does not print hex value for a uint64_t

My code is this (main.c): 我的代码是这样的(main.c):

#include <inttypes.h>
#include <stdio.h>


int
main(int argc, char **argv)
{
 uint64_t n;

 n = UINT64_MAX;

 printf("%" PRIX64 " %" PRIu64 "\n", n, n);

 return 0;
}

The output of the program is this: 该程序的输出是这样的:

FFFFFFFFFFFFFFFF 18446744073709551615

But I am looking for this: 但是我正在寻找这个:

10000000000000000 18446744073709551615

I am using GCC (gcc -std=c99 main.c): gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5 我正在使用GCC(gcc -std = c99 main.c):gcc(Ubuntu / Linaro 4.4.4-14ubuntu5)4.4.5

Looking for an answer in google gave me this: http://bytes.com/topic/c/answers/565055-convert-64-integer-hex-octet-string 寻找在谷歌的答案给我这个: http : //bytes.com/topic/c/answers/565055-convert-64-integer-hex-octet-string

Now, I am lost. 现在,我迷路了。 What am I doing wrong? 我究竟做错了什么?

the value of UINT64_MAX should be 0xffffffffffffffff as that is the value of 64-bits all set. UINT64_MAX的值应为0xffffffffffffffff因为这是全部设置的64位值。 I don't understand why you expect 0x10000000000000000 (which requires 65-bits to represent ). 我不明白您为什么期望0x10000000000000000 (需要65位来表示 )。

Also 18446744073709551615 in decimal is equal to 0xffffffffffffffff , so printf is doing the right thing. 同样,十进制的18446744073709551615等于0xffffffffffffffff ,所以printf做正确的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM