Elias Delta Coding

Source: Internet
Author: User

Eliasdelta Coding

Applicability:

Like eliasdeltacoding and eliasgamma coding, eliasdeltacoding is a unified encoding of positive integers, invented by peterelias. It is applicable to situations where the maximum encoded integer cannot be known in advance, and small integers are frequently used and large integers are frequently used.

 

Encoding Principle:

For any positive integer num, the INT (log2 (Num) + 1 is gamma encoded, And the num binary string on the suffix removes the highest substring. For example, 5 is encoded as 011,01.

 

Encoding example:

Num

Eliasdelta code

Implied Probability

1 = 20 +0

1

1/2

2 = 21 +0

0100

1/16

3 = 21 +1

0101

1/16

4 = 22 +0

01100

1/32

5 = 22 +1

01101

1/32

6 = 22 +2

01110

1/32

7 = 22 +3

01111

1/32

8 = 23 +0

00100000

1/256

9 = 23 +1

00100001

1/256

Encoding and decoding algorithms:

/****************************************************Encode_EliasDelta:Encoding algorithm of EliasDelta Coding.*****************************************************/int Encode_EliasDelta(int *pSourceData,char *pEncodedData,int nSourceDataLen,int &nEncodedDataLen){int k=-1; for(int i=0;i<nSourceDataLen;i++) {        int num = pSourceData[i];        int numPow= int(log10(num)/log10(2));int num1 = numPow+1;int num1Pow= int(log10(num1)/log10(2));for (int j=0; j <num1Pow ; j++)     pEncodedData[++k]=0;pEncodedData[++k]=1;                     for (j=num1Pow-1; j >= 0; j--)              {            if (num1 & 1 << j)   pEncodedData[++k]=1;            else                 pEncodedData[++k]=0;}        for (j=numPow-1; j >= 0; j--)              {            if (num & 1 << j)    pEncodedData[++k]=1;            else                 pEncodedData[++k]=0;        }nEncodedDataLen=k+1;}return 1;}/****************************************************Decode_EliasDelta:Decoding algorithm of EliasDelta Coding.*****************************************************/int Decode_EliasDelta(int *pDecodedData,char *pEncodedData,int &nDecodedDataLen,int nEncodedDataLen){int i=0,j=0;while (1)    {//Decode num1        int num1Pow = 0;        while (!pEncodedData[i++])   num1Pow++; if(num1Pow >=48)          break;      int num1 = 0;        for (int h=num1Pow-1; h >= 0; h--)if (pEncodedData[i++])    num1 |= 1 << h;        num1 |= 1 << num1Pow; //Decode numint numPow = 0;numPow = num1-1;int num =0;for( h=numPow-1;h>=0;h--){if(pEncodedData[i++])num |= 1 <

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.