/// <summary> /// Reads an encoded value from a <see cref="BitReader"/>. /// </summary> public int Read(BitReader reader) { var u = Codes.UnaryZeros.Read(reader) - 1; var len = (int)((reader.Read(u) | (1ul << u)) - 1); return((int)(reader.Read(len) | (1ul << len))); }
/// <summary> /// Reads an encoded value from a <see cref="BitReader"/>. /// </summary> public int Read(BitReader reader) { int value = (int)reader.Read(bits - 1); if (value < extra) { return(value); } return(value * 2 + (int)reader.Read(1) - extra); }
/// <summary> /// Gets the value corresponding to a code. /// </summary> public int Read(BitReader reader) { int value = 1; while (reader.Read(1) != 0) { value = (int)(reader.Read(value) | (1UL << value)); } return(value); }
/// <summary> /// Reads an encoded value from a <see cref="BitReader"/>. /// </summary> public int Read(BitReader reader) { int f = Codes.Fibonacci.Read(reader) - 1; int value = (int)reader.Read(f); return(value | (1 << f)); }
/// <summary> /// Gets the value corresponding to a Fibonacci code. /// </summary> public int Read(BitReader reader) { int value = 0; int f = 0; bool bit = false; while (true) { if (reader.Read(1) == 0) { bit = false; } else if (bit) { break; } else { bit = true; value += fib[f]; } f++; } return(value); }
public void BitStreamTest() { var g = new Generator("BitStreamTest"); var codes = new List <Code>(); for (int i = 0; i < 10000; i++) { var bits = g.UInt64(); var length = g.Int32(65); bits >>= 64 - length; var code = new Code(bits, length); codes.Add(code); } var writer = new BitWriter(1000); foreach (var code in codes) { writer.Write(code); } var buffer = writer.ToArray(); var reader = new BitReader(buffer); foreach (var code in codes) { ulong bits = reader.Read(code.Length); Assert.AreEqual(code.Bits, bits); } }
/// <summary> /// Reads an encoded value from a <see cref="BitReader"/>. /// </summary> public int Read(BitReader reader) { int value = 1; while ((int)reader.Read(1) == tally) { value++; } return(value); }
/// <summary> /// Gets the value corresponding to a code. /// </summary> public int Read(BitReader reader) { int value = 0; int power = 1; while (true) { bool done = reader.Read(1) == 0; value += power * encoding.Read(reader); if (done) { return(value); } power *= n; } }
/// <summary> /// Reads an encoded value from a <see cref="BitReader"/>. /// </summary> public int Read(BitReader reader) { int u = Codes.UnaryOnes.Read(reader) - 1; if (u == 0) { return(0); } int value = 1; while (--u > 0) { value = (int)reader.Read(value) | (1 << value); } return(value); }
/// <summary> /// Reads an encoded value from a <see cref="BitReader"/>. /// </summary> public int Read(BitReader reader) { var u = Codes.UnaryZeros.Read(reader) - 1; return((int)reader.Read(u) | (1 << u)); }
/// <summary> /// Gets the value corresponding to a code. /// </summary> public int Read(BitReader reader) { return((int)reader.Read(bitCount)); }
/// <summary> /// Reads an encoded value from a <see cref="BitReader"/>. /// </summary> public int Read(BitReader reader) { int u = Codes.UnaryOnes.Read(reader) - 1; return((int)reader.Read(exponentOf2) + (u << exponentOf2)); }