1、使用 "%llu"格式说明符 - #include <stdio.h>
- #include <stdint.h>
- int main() {
- uint64_t value = 0x123456789ABCDEF0;
- // 使用 %llu 打印十六进制
- printf("Hexadecimal (lowercase): %llx\n", value);
- printf("Hexadecimal (uppercase): %llX\n", value);
- return 0;
- }
复制代码
2、使用PRIx64 和 PRIu64 宏(需要头文件 inttypes.h,支持跨平台) - #include <stdio.h>
- #include <stdint.h>
- #include <inttypes.h> // 包含 inttypes.h 以使用 PRIx64 和 PRIu64
- int main() {
- uint64_t value = 0x123456789ABCDEF0;
- // 使用 PRIx64 打印十六进制
- printf("Hexadecimal (lowercase): %" PRIx64 "\n", value);
- printf("Hexadecimal (uppercase): %" PRIX64 "\n", value);
- // 使用 PRIu64 打印十进制
- printf("Decimal: %" PRIu64 "\n", value);
- return 0;
- }
复制代码 |