赞
踩
移位操作:因为运算符优先级的原因,注意加括号。还有没必要在移位的时候进行(uint32_t)转换。
测试程序如下:
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <stdint.h>
-
- int main()
- {
- uint8_t buffer[4] = {0x11, 0x22, 0x33, 0x44};
- uint32_t value = buffer[0] + (buffer[1] << 8) + (buffer[2] << 16) + (buffer[3] << 24);
-
- printf("value = %x\n", value);
-
- return 0;
- }
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <stdint.h>
-
- int main()
- {
- uint8_t buffer[4] = {0x11, 0x22, 0x33, 0x44};
- uint32_t value = buffer[0] + buffer[1] << 8 + buffer[2] << 16 + buffer[3] << 24;
-
- printf("value = %x\n", value);
-
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。