1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include<stdint.h> #include<stdlib.h> uint32_t pack_uint32(char* data) { uint16_t num = 0x0102; char c2[2] = {0x01, 0x02}; uint16_t num2 = *(uint16_t*)c2; if (num == num2) { //这个判断的结果可以保存到一个static变量里面,方便下次使用 return *(uint32_t*)data; } char c4[4] = {data[3], data[2], data[1], data[0]}; return *(uint32_t*)c4; } |