向 quint8類型數(shù)據(jù)中連續(xù)位寫(xiě)入數(shù)值
目前成都創(chuàng)新互聯(lián)已為上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、網(wǎng)站托管、服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計(jì)、印江網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。void Utils::insertValueToQuint8CtrlWord(quint8* unsigned8CtrlWord, int high_position, int low_postion, quint16 setValue)
{int len = high_position - low_postion;
switch (len)
{case 0:
setValue = setValue & 0x00000001;
break;
case 1:
setValue = setValue & 0x00000003;
break;
case 2:
setValue = setValue & 0x00000007;
break;
case 3:
setValue = setValue & 0x0000000f;
break;
case 4:
setValue = setValue & 0x0000001f;
break;
case 5:
setValue = setValue & 0x0000003f;
break;
case 6:
setValue = setValue & 0x0000007f;
break;
case 7:
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類型數(shù)據(jù)中連續(xù)位讀取數(shù)值
int Utils::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;
}
說(shuō)明:quint16,quint32,quint64類型數(shù)據(jù)類似方法實(shí)現(xiàn)。
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
當(dāng)前標(biāo)題:C++中按位寫(xiě)入讀取數(shù)值-創(chuàng)新互聯(lián)
本文地址:http://aaarwkj.com/article16/ddohgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷型網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作、外貿(mào)建站、Google、自適應(yīng)網(wǎng)站、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容