admin 管理员组文章数量: 1184232
向 quint8类型数据中连续位写入数值
voidUtils::insertValueToQuint8CtrlWord(quint8* unsigned8CtrlWord,int high_position,int low_postion, quint16 setValue){int len = high_position - low_postion;switch(len){case0:
setValue = setValue &0x00000001;break;case1:
setValue = setValue &0x00000003;break;case2:
setValue = setValue &0x00000007;break;case3:
setValue = setValue &0x0000000f;break;case4:
setValue = setValue &0x0000001f;break;case5:
setValue = setValue &0x0000003f;break;case6:
setValue = setValue &0x0000007f;break;case7:
setValue = setValue &0x000000ff;break;default:break;}
bitset<32>binaryControlWord(*unsigned8CtrlWord);for(int i = low_postion; i <= high_position; i++){
binaryControlWord.reset(i);}
bitset<32>binaryValue(setValue);
binaryValue <<= low_postion;
binaryControlWord |= binaryValue;*unsigned8CtrlWord =(quint32)binaryControlWord.to_ulong();}从 quint8类型数据中连续位读取数值
intUtils::getValueFromQuint8CtrlWord(quint8* unsigned8CtrlWord,int high_position,int low_postion){int ret =0;
bitset<16>binaryCtrlWord(*unsigned8CtrlWord);for(int i =0; i < low_postion; i++) binaryCtrlWord.reset(i);for(int i = high_position +1; i <=7; i++) binaryCtrlWord.reset(i);
binaryCtrlWord >>= low_postion;
ret =(quint8)binaryCtrlWord.to_ulong();return ret;}说明:quint16,quint32,quint64类型数据类似方法实现。
版权声明:本文标题:位操作技巧 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1773851106a3566443.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论