rand() & 0xFF 是什么意思?

rand()随机数函数返回一个int型的数,之后用这个数逻辑与上一个0xff,最后将结果赋值给val;
例如:
rand()函数返回值为8;8的2进制形式为0000,0000,0000,0000,0000,0000,0000,1000
0xff的2进制形式为0000,0000,0000,0000,1111,1111,1111,1111
两个数作为运算‘&‘
之后得到0000,0000,0000,0000,0000,0000,0000,1000
然后将这个数赋值给m_session

整个这条语句的作用就是将rand()返回值的高16位变成0,低16位不变
————————————————
版权声明:本文为CSDN博主「Li Shi」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wonderful931106/article/details/121289914

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
逐句翻译这段代码if (board_channel_number == 2) { int cnt0 = 0; for (int j = spos*4; cnt0 < cnt && j + 3 < netBuffer.size(); j += 4,cnt0++) { y[0].push_back(static_cast<double>(((netBuffer[j + 0] & 0xFF) | (netBuffer[j + 1] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); // //(rand()%300); y[1].push_back(static_cast<double>(((netBuffer[j + 2] & 0xFF) | (netBuffer[j + 3] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); //(rand()%500) } cnt = cnt0; } else if (board_channel_number == MAX_CHANNEL) { int cnt0 = 0; for (int j = spos*12;cnt0<cnt&& j + 11 < netBuffer.size(); j += 12,cnt0++) { y[0].push_back(static_cast<double>((netBuffer[j + 0] & 0xFF | (netBuffer[j + 1] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); // //(rand()%300); y[1].push_back(static_cast<double>((netBuffer[j + 2] & 0xFF | (netBuffer[j + 3] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); //(rand()%500); y[2].push_back(static_cast<double>((netBuffer[j + 4] & 0xFF | (netBuffer[j + 5] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); y[3].push_back(static_cast<double>((netBuffer[j + 6] & 0xFF | (netBuffer[j + 7] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); y[4].push_back(static_cast<double>((netBuffer[j + 8] & 0xFF | (netBuffer[j + 9] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); y[5].push_back(static_cast<double>((netBuffer[j + 10] & 0xFF | (netBuffer[j + 11] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); } cnt = cnt0; } x.resize(y[0].size()); for (size_t i = 0; i < x.size(); i++) { x[i] = i+spos; } for (size_t i = 0; i < board_channel_number; i++) { newWin->graph(i)->setData(x, y[i]); newWin->graph(i)->setPen(QPen(color[i])); } newWin->replot(QCustomPlot::rpQueuedReplot); }
最新发布
07-11
如果(board_channel_number == 2) { int cnt0 = 0; for (int j = spos*4; cnt0 < cnt && j + 3 < netBuffer.size(); j += 4,cnt0++) { y[0].push_back(static_cast<double>(((netBuffer[j + 0] & 0xFF) | (netBuffer[j + 1] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); // //(rand()%300); y[1].push_back(static_cast<double>(((netBuffer[j + 2] & 0xFF) | (netBuffer[j + 3] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); //(rand()%500) } cnt = cnt0; } else if (board_channel_number == MAX_CHANNEL) { int cnt0 = 0; for (int j = spos*12;cnt0<cnt&& j + 11 < netBuffer.size(); j += 12,cnt0++) { y[0].push_back(static_cast<double>((netBuffer[j + 0] & 0xFF | (netBuffer[j + 1] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); // //(rand()%300); y[1].push_back(static_cast<double>((netBuffer[j + 2] & 0xFF | (netBuffer[j + 3] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); //(rand()%500); y[2].push_back(static_cast<double>((netBuffer[j + 4] & 0xFF | (netBuffer[j + 5] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); y[3].push_back(static_cast<double>((netBuffer[j + 6] & 0xFF | (netBuffer[j + 7] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); y[4].push_back(static_cast<double>((netBuffer[j + 8] & 0xFF | (netBuffer[j + 9] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); y[5].push_back(static_cast<double>((netBuffer[j + 10] & 0xFF | (netBuffer[j + 11] << 8)) * board_input_range[0] * 2 / qPow(2, board_resolution))); } cnt = cnt0; } x.resize(y[0].size()); for (size_t i = 0; i < x.size(); i++) { x[i] = i+spos; } for (size_t i = 0; i < board_channel_number; i++) { newWin->graph(i)->setData(x, y[i]); newWin->graph(i)->setPen(QPen(color[i])); } newWin->replot(QCustomPlot::rpQueuedReplot);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值