Beispiel #1
0
        public static void WriteBitCode64(this Stream stream, BitCode64 code)
        {
            stream.WriteUInt64(code.Code);
            byte len = ((byte)code.Length).SetBit(7, code.High);

            stream.WriteByte(len);
        }
        public static int ReadGammaCode(this BitCode64 code)
        {
            int l2 = code.Length - 1;

            if (code.High)
            {
                return((int)(code.Code >> (63 - l2)) - 1);
            }
            else
            {
                return((int)code.Code - 1);
            }
        }
        public static int ReadDeltaCode(this BitCode64 code)
        {
            int    ll = 0;
            int    i  = 63;
            UInt64 ucode;

            if (code.High)
            {
                ucode = code.Code;
            }
            else
            {
                ucode = code.Code << 64 - code.Length;
            }

            if (ucode == 0x8000000000000000)
            {
                return(0);
            }

            while (!ucode.GetBit(i--))
            {
                ll++;
            }
            int l = code.Length - 1 - ll - ll;

            ll += ll;
            int high = ((int)(ucode >> (63 - ll))) - 1;
            int v    = 2;

            while (--high > 0)
            {
                v += v;
            }
            int low = (int)((ucode << (ll + 1)) >> (64 - l));

            return(v + low - 1);
        }
 public static void WriteCode(this IBitStream stream, BitCode64 code)
 {
     stream.WriteBits(code.Code, code.Length, code.High);
 }