Beispiel #1
0
        public static string Bit6Extract(byte[] data)
        {
            BitExtract    extract = new BitExtract(data);
            StringBuilder result  = new StringBuilder();

            while (true)
            {
                List <bool> bits = extract.GetBits(6);
                if (bits.Count < 6)
                {
                    break;
                }

                char ch = (char)BitExtract.ToByte(bits, 6);

                // 如果正好末尾是 6 bits 100000,需丢弃
                // 注意测试这种情形, 应正确丢弃
                if (extract.Count == 0 && ch == 0x20)
                {
                    break;
                }

                if ((ch & 0x20) == 0x00)
                {
                    ch = (char)(ch | 0x40);
                }
                result.Append(ch);
            }
            return(result.ToString());
        }
Beispiel #2
0
        public static string Bit7Extract(byte[] data)
        {
            BitExtract    extract = new BitExtract(data);
            StringBuilder result  = new StringBuilder();

            while (true)
            {
                List <bool> bits = extract.GetBits(7);
                if (bits.Count < 7)
                {
                    break;
                }

                char ch = (char)BitExtract.ToByte(bits, 7);

                // 正好末尾是 7 bits 1111111,需要丢弃
                // TODO: 注意测试这种情况
                if (extract.Count == 0 && ch == 0x7f)
                {
                    break;
                }

                result.Append(ch);
            }

            return(result.ToString());
        }
Beispiel #3
0
        public static string Bit5Extract(byte[] data)
        {
            BitExtract    extract = new BitExtract(data);
            StringBuilder result  = new StringBuilder();

            while (true)
            {
                List <bool> bits = extract.GetBits(5);
                if (bits.Count < 5)
                {
                    break;
                }
                if (BitExtract.IsZero(bits))
                {
                    break;
                }
                char ch = (char)(BitExtract.ToByte(bits, 5) | 0x40);
                result.Append(ch);
            }
            return(result.ToString());
        }