Example #1
0
        public static void MainTest(string[] args)
        {
            int bytesPerLine = 16;

            if (args.Length == 1)
            {
                bytesPerLine = int.Parse(args[0]);
            }
            BinaryInput input;

            if (args.Length == 2)
            {
                input = new BinaryInput(args[1]);
            }
            else
            {
                input = new BinaryInput();
            }
            int i;

            for (i = 0; !input.IsEmpty; i++)
            {
                if (bytesPerLine == 0)
                {
                    input.ReadChar();
                    continue;
                }
                if (i == 0)
                {
                    Console.Write("");
                }
                else if (i % bytesPerLine == 0)
                {
                    Console.Write("\n", i);
                }
                else
                {
                    Console.Write(" ");
                }
                char c = input.ReadChar();
                Console.Write("{0:X2}", c & 0xff);
            }
            if (bytesPerLine != 0)
            {
                Console.WriteLine();
            }
            Console.WriteLine((i * 8) + " bits");
        }
Example #2
0
        public static void MainTest(string[] args)
        {
            BinaryInput  input  = new BinaryInput();
            BinaryOutput output = new BinaryOutput(args[0]);

            // read one 8-bit char at a time
            while (!input.IsEmpty)
            {
                int c = input.ReadChar();
                if (c == -1)
                {
                    break;
                }
                output.Write((byte)c);
            }
            output.Close();
        }
Example #3
0
        public static void MainTest(string[] args)
        {
            int bitsPerLine = 16;

            if (args.Length == 1)
            {
                bitsPerLine = int.Parse(args[0]);
            }
            BinaryInput input = new BinaryInput();

            int count;

            for (count = 0; !input.IsEmpty; count++)
            {
                if (bitsPerLine == 0)
                {
                    input.ReadBoolean();
                    continue;
                }
                else if (count != 0 && count % bitsPerLine == 0)
                {
                    Console.WriteLine();
                }
                if (input.ReadBoolean())
                {
                    Console.Write(1);
                }
                else
                {
                    Console.Write(0);
                }
            }
            if (bitsPerLine != 0)
            {
                Console.WriteLine();
            }
            Console.WriteLine(count + " bits");
        }
Example #4
0
File: LZW.cs Project: zzhi/Algs4Net
 /// <summary>
 /// Uses file names to direct input and output
 /// </summary>
 /// <param name="outputFileName">user input file, empty if from console</param>
 /// <param name="inputFileName">user output file</param>
 public LZW(string inputFileName, string outputFileName)
 {
     //Console.WriteLine("LZW with InFile={0} and OutFile={1}", inputFileName, outputFileName);
     input  = new BinaryInput(inputFileName);
     output = new BinaryOutput(outputFileName);
 }