natix.CompactDS.BinaryCoding.Encode C# (CSharp) Method

Encode() public method

public Encode ( BitStream32 Buffer, int u ) : void
Buffer BitStream32
u int
return void
        public void Encode(BitStream32 Buffer, int u)
        {
            if (u < 0) {
                var message = String.Format ("Negative numbers are not valid for BinaryCoding, u: {0}", u);
                throw new ArgumentOutOfRangeException (message);
            }
            int mask = 1 << this.NumBits;
            if (u >= mask) {
                var message = String.Format ("Number too large for {0} bits BinaryCoding, {1} >= {2}",
                    this.NumBits, u, mask);
                throw new ArgumentOutOfRangeException (message);
            }
            --mask;
            u &= mask;
            Buffer.Write(u, this.NumBits);
        }