符号なしコロンブス符号化の復号原理及びC++実現

2152 ワード

コロンブス符号化コードワードcode_wordは3つの部分から構成されています.
code_word=[M個0]+[1]+[Info]
ここで、Infoは情報を携帯するMビットデータであり、各コロンブス符号の長さは(2 M+1)ビットであり、各符号語はcode_num生成.
コードワードcode_によるword復号出code_num値のプロセスは次のとおりです.

  • まず、Mビットが「1」で終わる0を読み込む.

  • 得られたMに基づいて、次のMビットInfoデータを読み込む.

  • この式に基づいて計算結果code_を得るnum = Info – 1 + 2M

  • 以上のプロセスのC++実装コードは以下の通りである.
     
    /*******************************************************************************
    * : GetUeValue
    * : ;
    * : pBuff -- ;
    * nLen -- ;
    * nStartBit -- bit ;
    * : nStartBit -- bit ;
    * : 。
    * :
    *
    * ------------------------------------------------------------------------------
    * 2010-07-19
    ******************************************************************************
    */
    UINT GetUeValue(BYTE *pBuff, UINT nLen, UINT &nStartBit)
    {
    // 0bit
    UINT nZeroNum = 0;
    while (nStartBit < nLen * 8)
    {
    if (pBuff[nStartBit / 8] & (0x80 >> (nStartBit % 8)))
    {
    break;
    }
    nZeroNum++;
    nStartBit++;
    }
    nStartBit ++;

    //
    DWORD dwRet = 0;
    for (UINT i=0; i<nZeroNum; i++)
    {
    dwRet <<= 1;
    if (pBuff[nStartBit / 8] & (0x80 >> (nStartBit % 8)))
    {
    dwRet += 1;
    }
    nStartBit++;
    }
    return (1 << nZeroNum) - 1 + dwRet;
    }