struct ControlWindowMsg{
unsigned char buf1;
unsigned char buf2;
unsigned char buf3;
unsigned char buf4;
};
char buf[4] = {0};
buf[0] = 1 & 0xff;
buf[1] = 0 & 0xff;
buf[2] = 3 & 0xff;
buf[3] = 104 &0xff;
struct ControlWindowMsg windowMsg;
memset(&windowMsg, 0, sizeof(windowMsg)); //结构体赋值为0
memcpy(&windowMsg, buf, sizeof(windowMsg)); //结构体赋值
NSTimeInterval timeInerval = [[NSDate date] timeIntervalSince1970];
int taskId = [[NSString stringWithFormat:@"%f",timeInerval] intValue];
buf[2] = taskId & 0xff;
buf[3] = (taskId >> 8) & 0xff;
buf[4] = (taskId >> 16) & 0xff;
buf[5] = (taskId >> 24) & 0xff;
本文深入探讨了如何定义结构体并将其与字符数组进行有效赋值,包括使用memcpy函数的操作,以及如何利用时间戳对特定变量进行编码。

2万+

被折叠的 条评论
为什么被折叠?



