All pastes #171762 Raw Edit

v

public text v1 · immutable
·published 2006-09-15 16:45 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(DebugOutput(
                StrByteArray("JKFlksfjeoska893892FDLSlkjlkJKFlksfjeoska893892FDLSlkjlkJKFlksfjeoska893892FDLSlkjlkJKFlksfjeoska893892FDLSlkjlkJKFlksfjeoska893892FDLSlkjlkJKFlksfjeoska893892FDLSlkjlkJKFlksfjeoska893892FDLSlkjlk")
                ));

            Console.ReadLine();
        }

        public static byte[] StrByteArray(string str)
        {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            return encoding.GetBytes(str);
        }

        // TehUser[vL]
        public static string DebugOutput(byte[] bytesIn)
        {
            String strOut = "";
            String strText = "", strBytes = "";

            for (int i = 0; i < bytesIn.Length; i++)
            {
                if ((i % 16) == 0) strOut += String.Format("{0:X4}:  ", i);

                strBytes += String.Format("{0:X2} ", bytesIn[i]);

                switch (bytesIn[i])
                {
                    case 0:
                    case 9:
                    case 10:
                    case 13:
                        strText += ".";
                        break;
                    default:
                        strText += (char)bytesIn[i];
                        break;
                }

                if (((i + 1) % 16 == 0) || (i == bytesIn.Length - 1))
                {
                    if (strBytes.Length < 48) strBytes = strBytes.PadRight(48, ' ');
                    if (strText.Length < 16) strText = strText.PadRight(16, '.');
                    strOut += strBytes + " " + strText + (i == (bytesIn.Length - 1) ? ((char)bytesIn[i]).ToString() : "") + "\n";
                    strBytes = "";
                    strText = "";
                }
            }

            Console.WriteLine("Length: {0}\n", bytesIn.Length);

            strOut = strOut.Remove(strOut.Length - 2); // Remove the last newline.

            return strOut;
        }
    }
}