char buffer[8];
memcpy(&buffer[0], "02000000", 8); //copy without '\0' 如何将缓冲区中的字节解释为0x00000002,并将其放入int类型的变量中?
发布于 2013-10-22 07:08:58
您将它变成一个字符串(使用终止的'\0'),并使用strtol来转换它。
字节交换整数很简单:
#define SWAP16(x) (((x) & 0xff00) >> 8) | (((x) & 0x00ff) << 8)
#define SWAP32(x) (SWAP16(((x) & 0xffff0000) >> 16)) | (SWAP16((x) & 0x0000ffff) << 16)
uint32_t value = SWAP32(strtol("02000000", NULL, 16));https://stackoverflow.com/questions/19511247
复制相似问题