/// <summary>
 /// Writes a 32 bit signed integer
 /// </summary>
 public void Write(UInt32 source, int numberOfBits)
 {
     Debug.CheckArgument((numberOfBits > 0 && numberOfBits <= 32), "Write(uint, numberOfBits) can only write between 1 and 32 bits");
     EnsureBufferSize(m_bitLength + numberOfBits);
     BitWriter.WriteUInt32(source, numberOfBits, m_data, m_bitLength);
     m_bitLength += numberOfBits;
 }
        /// <summary>
        /// Writes a 32 bit signed integer
        /// </summary>
        public unsafe void Write(Int32 source)
        {
            EnsureBufferSize(m_bitLength + 32);

            // can write fast?
            if (m_bitLength % 8 == 0)
            {
                fixed(byte *numRef = &Data[m_bitLength / 8])
                {
                    *((int *)numRef) = source;
                }
            }
            else
            {
                BitWriter.WriteUInt32((UInt32)source, 32, Data, m_bitLength);
            }
            m_bitLength += 32;
        }
        /// <summary>
        /// Writes a signed integer using 1 to 32 bits
        /// </summary>
        public void Write(Int32 source, int numberOfBits)
        {
            Debug.CheckArgument((numberOfBits > 0 && numberOfBits <= 32), "Write(int, numberOfBits) can only write between 1 and 32 bits");
            EnsureBufferSize(m_bitLength + numberOfBits);

            if (numberOfBits != 32)
            {
                // make first bit sign
                int signBit = 1 << (numberOfBits - 1);
                if (source < 0)
                {
                    source = (-source - 1) | signBit;
                }
                else
                {
                    source &= (~signBit);
                }
            }

            BitWriter.WriteUInt32((uint)source, numberOfBits, m_data, m_bitLength);

            m_bitLength += numberOfBits;
        }
 /// <summary>
 /// Writes a 32 bit unsigned integer
 /// </summary>
 public void Write(UInt32 source)
 {
     EnsureBufferSize(m_bitLength + 32);
     BitWriter.WriteUInt32(source, 32, m_data, m_bitLength);
     m_bitLength += 32;
 }