c - 如何打印 5 字节整数值?

标签 c

我刚刚开始阅读 C 并且有一个关于宏的问题。
如何打印一个 5 字节的整数值(恰好在宏中定义)? 例如:

#define MAX 0xdeadbeaf12
int main(){
printf(" 0x %2x \n", MAX);
}  

此代码打印 adbeaf12 但不打印 deadbeaf12。

如何打印所有字节?

最佳答案

我更愿意对变量的大小做出明确的假设。下面使用标准(尽管经常未使用)宏来定义 64 位常量并将这样的量打印为十六进制值。

#include <stdio.h>

// Pull in UINT64_C and PRIx64 macros
#include <inttypes.h>

// Make this a 64-bit literal value
#define MAX UINT64_C(0xdeadbeaf12)

int main()
{
    // Use PRIx64 which inserts the correct printf specifier for
    // a hex format of a 64-bit value
    printf(" 0x%" PRIx64 " \n", MAX);
}

关于c - 如何打印 5 字节整数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2672963/

相关文章:

objective-c - 使用 0.5 规则舍入 float 的方法

c - 解析 CSV 文件问题

用负整数进行计数排序?

无法在数组中拆分和存储十六进制字符串

Codeblocks 编译和运行有效,但点击 exe 不

c - ANSI C : converting argv into int

c - 使用 FFTW 的相位相关

当枚举和标识符列表的长度不匹配时导致编译器错误

c - 缓冲区溢出,修改了 Seedlab 问题?

c - 使用 CC 编译器 (Solaris) 时链接 unistd.h