十六进制格式的无符号长整型打印

时间:2022-10-15 16:44:22

I am trying to print out an unsigned long long like this:

我试图打印出这样的unsigned long long:

  printf("Hex add is: 0x%ux ", hexAdd);

but I am getting type conversion errors since I have an unsigned long long.

但我得到类型转换错误,因为我有一个unsigned long long。

3 个解决方案

#1


59  

You can use the same ll size modifier for %x, thus:

您可以对%x使用相同的ll size修饰符,因此:

#include <stdio.h>

int main() {
    unsigned long long x = 123456789012345ULL;
    printf("%llx\n", x);
    return 0;
}

The full range of conversion and formatting specifiers is in a great table here:

完整的转换和格式化说明符在这里有一个很好的表:

#2


4  

try %llu - this will be long long unsigned in decimal form

尝试%llu - 这将是十进制长的无符号长整数

%llx prints long long unsigned in hex

%llx以十六进制格式打印long long unsigned

#3


2  

printf("Hex add is: %llu", hexAdd);

#1


59  

You can use the same ll size modifier for %x, thus:

您可以对%x使用相同的ll size修饰符,因此:

#include <stdio.h>

int main() {
    unsigned long long x = 123456789012345ULL;
    printf("%llx\n", x);
    return 0;
}

The full range of conversion and formatting specifiers is in a great table here:

完整的转换和格式化说明符在这里有一个很好的表:

#2


4  

try %llu - this will be long long unsigned in decimal form

尝试%llu - 这将是十进制长的无符号长整数

%llx prints long long unsigned in hex

%llx以十六进制格式打印long long unsigned

#3


2  

printf("Hex add is: %llu", hexAdd);