写了一个大小端转换的代码
int x =recv(sockConn, (char*)buf, len, 0);
cout << "data read:" << x << endl;
for(int i = 0; i < 30; i++)
cout << hex << (int)buf[i] << endl;
frameInfo info; //info.resolutionWidth = buf[0] << 8 +buf[1]; //之前每个语句都如上面这句,结果不对,info.resolutionWidth = (buf[0] << 8) +buf[1];info.resolutionHeight = (buf[2] << 8) + buf[3];info.x = (buf[4] << 8) + buf[5];info.y =(buf[6] << 8) + buf[7];info.w =
(buf[8] << 8) + buf[9];info.h = (buf[10] << 8) + buf[11];cout <<dec<< info.resolutionHeight << endl;cout << info.resolutionWidth << endl;cout << info.w << endl;
运行结果怎么都不是期望的方式,后来发现,左移运算符优先级低于加号运算符,加括号解决问题
4603

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



