当前位置: 首页>>代码示例>>C#>>正文


C# Buffer.BitsLeft方法代码示例

本文整理汇总了C#中System.Buffer.BitsLeft方法的典型用法代码示例。如果您正苦于以下问题:C# Buffer.BitsLeft方法的具体用法?C# Buffer.BitsLeft怎么用?C# Buffer.BitsLeft使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Buffer的用法示例。


在下文中一共展示了Buffer.BitsLeft方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Insert

		public static bool Insert(Buffer dest, Buffer source)
		{
			if (dest.BitsLeft() < source.BitsLeft())
				return false;

			Bitstream.Buffer tmp = new Bitstream.Buffer();
			Copy(tmp, source);

			while (tmp.BitsLeft() > 0)
			{
				if (tmp.bitpos > 0)
				{
					uint bits = (uint)(8 - tmp.bitpos);
					if (bits > tmp.BitsLeft())
					{
						bits = tmp.BitsLeft();
					}
					Bitstream.PutBits(dest, bits, Bitstream.ReadBits(tmp, bits));
				}
				if (tmp.BitsLeft() > 32)
					Bitstream.PutBits(dest, 32, Bitstream.ReadBits(tmp, 32));

				uint left = tmp.BitsLeft();
				if (left >= 8)
				{
					Bitstream.PutBits(dest, 8, Bitstream.ReadBits(tmp, 8));
				}
				else if (left > 0)
				{
					Bitstream.PutBits(dest, left, Bitstream.ReadBits(tmp, left));
				}
			}
			return true;
		}
开发者ID:raxptor,项目名称:putki,代码行数:34,代码来源:Bitstream.cs

示例2: PutBits

        public static bool PutBits(Buffer buf, int bits, UInt32 value)
        {
            if (buf.BitsLeft() < bits)
            {
                buf.error = 1;
                return false;
            }

            if (bits > 8)
            {
                PutBits(buf, 8, value & 0xff);
                PutBits(buf, bits - 8, value >> 8);
                return true;
            }

            if (buf.bitpos == 0)
            {
                buf.buf[buf.bytepos] = (byte)(value & s_bitmask[bits]);
                if (bits == 8)
                    buf.bytepos++;
                else
                    buf.bitpos = bits;
            }
            else
            {
                int room = 8 - buf.bitpos;
                if (bits <= room)
                {
                    byte mixin = (byte)((value & s_bitmask[bits]) << buf.bitpos);
                    buf.buf[buf.bytepos] = (byte)(buf.buf[buf.bytepos] | mixin);
                    buf.bitpos += bits;
                    if (buf.bitpos == 8)
                    {
                        buf.bitpos = 0;
                        buf.bytepos++;
                    }
                }
                else
                {
                    PutBits(buf, room, value);
                    return PutBits(buf, bits - room, value >> room);
                }
            }

            return true;
        }
开发者ID:raxptor,项目名称:putki-historical,代码行数:46,代码来源:Bitstream.cs

示例3: ReadBits

		public static UInt32 ReadBits(Buffer buf, uint bits)
		{
			if (buf.BitsLeft() < bits)
			{
				buf.error = 1;
				return 0;
			}
			CheatEntry ce = CheatTable[bits * 8 + buf.bitpos];
			uint dpos = buf.bytepos;
			byte[] data = buf.buf;
			buf.bitpos = ce.bitpos;
			buf.bytepos = dpos + ce.byteofs;
			uint value = ((uint)data[dpos] & ce.mfirst) >> ce.s0;
			if (ce.count == 2)
			{ 
				return value | ((uint)(data[dpos+1] & ce.mlast) << ce.s1);
			}
			else if (ce.count == 3)
			{ 
				return value | ((uint)(data[dpos+1]) << ce.s1)
				             | ((uint)(data[dpos+2] & ce.mlast) << ce.s2);
			}
			else if (ce.count == 4)
			{ 
				return value | ((uint)(data[dpos+1]) << ce.s1)
				             | ((uint)(data[dpos+2]) << ce.s2)
				             | ((uint)(data[dpos+3] & ce.mlast) << ce.s3);
			}
			else if (ce.count == 5)
			{ 
				return value | ((uint)(data[dpos+1]) << ce.s1)
				             | ((uint)(data[dpos+2]) << ce.s2)
				             | ((uint)(data[dpos+3]) << ce.s3)
				             | ((uint)(data[dpos+4] & ce.mlast) << ce.s4);
			}
			return value;
		}
开发者ID:raxptor,项目名称:putki,代码行数:37,代码来源:Bitstream.cs

示例4: ReadFloat

		public static float ReadFloat(Buffer buf)
		{
			if (buf.BitsLeft () < 32) {
				return 0;
			}
						
			byte[] tmp = new byte[4];
			for (int i = 0; i != 4; i++) {
				tmp[i] = (byte) ReadBits(buf, 8);
			}

			float[] f = new float[1];
			System.Buffer.BlockCopy(tmp, 0, f, 0, 4);
			return f[0];
		}
开发者ID:raxptor,项目名称:putki,代码行数:15,代码来源:Bitstream.cs

示例5: PutBits

		public static bool PutBits(Buffer buf, uint bits, uint value)
		{
			if (buf.BitsLeft() < bits)
			{
				buf.error = 1;
				return false;
			}

			PutBitsU(buf, bits, value);
			return true;
		}
开发者ID:raxptor,项目名称:putki,代码行数:11,代码来源:Bitstream.cs

示例6: ReadFloat

 public static float ReadFloat(Buffer buf)
 {
     SyncByte(buf);
     if (buf.BitsLeft() < 32)
         return 0;
     float f = BitConverter.ToSingle(buf.buf, buf.bytepos);
     buf.bytepos += 4;
     return f;
 }
开发者ID:raxptor,项目名称:putki-historical,代码行数:9,代码来源:Bitstream.cs

示例7: ReadBits

        public static UInt32 ReadBits(Buffer buf, int bits)
        {
            if (buf.BitsLeft() < bits)
            {
                buf.error = 1;
                return 0;
            }

            int max = 8 - buf.bitpos;
            if (bits <= max)
            {
                UInt32 val = ((UInt32)(buf.buf[buf.bytepos] >> buf.bitpos)) & s_bitmask[bits];
                buf.bitpos += bits;
                if (buf.bitpos == 8)
                {
                    buf.bitpos = 0;
                    buf.bytepos++;
                }
                return val;
            }

            return ReadBits(buf, max) | (ReadBits(buf, bits - max) << max);
        }
开发者ID:raxptor,项目名称:putki-historical,代码行数:23,代码来源:Bitstream.cs


注:本文中的System.Buffer.BitsLeft方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。