📄 bitpool.cpp
字号:
///////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "bitpool.h"
///////////////////////////////////////////////////////////////////////////////
//
CBitPool::CBitPool():m_offset(0),m_PlayedBits(0),m_playedOctets(0),
m_restBits(8),m_InWordAcumulated(0)
{
//pretty bad to alloc in the constructor
VERIFY(m_pDwBuff = new DWORD[BUFSIZE]);
}
///////////////////////////////////////////////////////////////////////////////
//
CBitPool::~CBitPool ()
{
delete[] m_pDwBuff;
m_pDwBuff = 0; // for debiger purpose
}
///////////////////////////////////////////////////////////////////////////////
// add 32 bits at the end
///////////////////////////////////////////////////////////////////////////////
//
void CBitPool::GoBackBits(int nBits)
{
m_PlayedBits -= nBits;
m_restBits += nBits;
while(m_restBits >= 8)
{
m_restBits -= 8;
m_playedOctets--;
}
}
///////////////////////////////////////////////////////////////////////////////
//
void CBitPool::GoBackOctets(int nOctets)
{
m_PlayedBits -= (nOctets*8);
m_playedOctets -= nOctets;
}
///////////////////////////////////////////////////////////////////////////////
//
//
DWORD CBitPool::GetBits(DWORD nBits)
{
m_PlayedBits += nBits;
DWORD dwRetVal = 0;
int contor = nBits;
while (contor > 0)
{
if (m_restBits == 0)
{
m_restBits = 8;
m_playedOctets++;
}
int minBidx = min((int)m_restBits,contor);
DWORD xmask = 0xFFFFFFFF >> (32 - m_restBits);
int tempVal = m_pDwBuff[m_playedOctets & 0xfff];
tempVal&= xmask;
m_restBits -= minBidx;
tempVal = tempVal >> m_restBits;
contor -= minBidx;
dwRetVal |= tempVal << contor;
}
return dwRetVal;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -