python - Python 包 ("<I"的 C 等效项是什么,0)

标签 python c endianness

我不太了解 python,但从文档中可以看出代码:

   str = "AAAA"
   str += pack("<I", 0)

会将 pack 函数的结果附加到 str,这将是小端格式的整数值 0。我的问题是这个的 C 等价物是什么。难道只是:

   char str[20] = "AAAA";
   strcat(str, "\x00");

?...

最佳答案

strcat() 在第一个 NUL 处停止,所以不会。

char str[20] = "AAAA";
int val = 0;
int nval = htole32(val);
memcpy(str + 4, (char*)&nval, 4);

关于python - Python 包 ("<I"的 C 等效项是什么,0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10771070/

相关文章:

Python Firebase 替换自动生成的 Key

python - 从 C+ 生成 TFRecord 格式数据

c++ - c语言makefile错误:Undefined symbols for architecture x86_64: "_main",引用自: 'main'

c - 在C中获取字符串的尾部

c++ - 为什么我的 TCP 传输在 cygwin 上损坏了?

python - 如何更新包哈希?

python - 循环遍历 Python 字典

c - 使用cachegrind和callgrind的不同读写计数

java - 如何使用 SeekableByteChannel 以小端格式读取和写入整数?

spring - PostGIS几何保存: "Invalid endian flag value encountered."