[C.C++] 【C/C++】C语言打印十六进制数据

371 0
Honkers 2025-4-2 15:43:08 | 显示全部楼层 |阅读模式

1、使用 "%llu"格式说明符

  1. #include <stdio.h>
  2. #include <stdint.h>
  3. int main() {
  4. uint64_t value = 0x123456789ABCDEF0;
  5. // 使用 %llu 打印十六进制
  6. printf("Hexadecimal (lowercase): %llx\n", value);
  7. printf("Hexadecimal (uppercase): %llX\n", value);
  8. return 0;
  9. }
复制代码

2、使用PRIx64 和 PRIu64 宏(需要头文件 inttypes.h,支持跨平台)

  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <inttypes.h> // 包含 inttypes.h 以使用 PRIx64 和 PRIu64
  4. int main() {
  5. uint64_t value = 0x123456789ABCDEF0;
  6. // 使用 PRIx64 打印十六进制
  7. printf("Hexadecimal (lowercase): %" PRIx64 "\n", value);
  8. printf("Hexadecimal (uppercase): %" PRIX64 "\n", value);
  9. // 使用 PRIu64 打印十进制
  10. printf("Decimal: %" PRIu64 "\n", value);
  11. return 0;
  12. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Honkers

荣誉红客

关注
  • 4010
    主题
  • 36
    粉丝
  • 0
    关注
这家伙很懒,什么都没留下!

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行