我是C++
编程新手。我正在尝试实现一个代码,通过它我可以从一个6
或多个individual bytes
.
我已经实现了相同的4 bytes
并且它正在工作
我的 4 字节代码:
char *command = "\x42\xa0\x82\xa1\x21\x22";
__int64 value;
value = (__int64)(((unsigned char)command[2] << 24) + ((unsigned char)command[3] << 16) + ((unsigned char)command[4] << 8) + (unsigned char)command[5]);
printf("%x %x %x %x %x",command[2], command[3], command[4], command[5], value);
使用此代码的值value
是82a12122
但是当我尝试做 6 个字节时结果是错误的。
6字节代码:
char *command = "\x42\xa0\x82\xa1\x21\x22";
__int64 value;
value = (__int64)(((unsigned char)command[0] << 40) + ((unsigned char)command[1] << 32) + ((unsigned char)command[2] << 24) + ((unsigned char)command[3] << 16) + ((unsigned char)command[4] << 8) + (unsigned char)command[5]);
printf("%x %x %x %x %x %x %x", command[0], command[1], command[2], command[3], command[4], command[5], value);
的输出值value
是82a163c2
错误的,我需要42a082a12122
. 那么谁能告诉我如何获得预期的输出以及6 Byte
代码有什么问题。
提前致谢。