本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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];
}
示例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;
}
示例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;
}
示例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);
}