Challenge19.BitWriter.ToString C# (CSharp) Method

ToString() public method

public ToString ( ) : string
return string
        public override string ToString()
        {
            if ( _buffer.Count > 0 )
                write();

            return _builder.ToString();
        }

Usage Example

        public static void Main( string[] args )
        {
            int[] values = GetInputValues( Console.ReadLine() );

            BitWriter writer = new BitWriter();

            int last = values[0];
            writer.Add( 1, 1 );
            writer.Add( last, 32 );

            for ( int i = 1; i < values.Length; i++ )
            {
                int v = values[i];
                int diff = v - last;

                if ( diff >= 16 || diff <= -17 )
                {
                    writer.Add( 1, 1 );
                    writer.Add( v, 32 );
                }
                else
                {
                    writer.Add( 0, 1 );
                    writer.Add( diff, 5 );
                }

                last = v;
            }

            PrintBase64Output( writer.ToString() );
        }