Nanook.QueenBee.ScriptEditor.bytesToHexAsciiString C# (CSharp) Method

bytesToHexAsciiString() private method

private bytesToHexAsciiString ( byte bytes ) : string
bytes byte
return string
        private string bytesToHexAsciiString(byte[] bytes)
        {
            StringBuilder sb = new StringBuilder();
            //char[] ch = new char[cl];

            for (int i = 0; i < bytes.Length; i++)
            {

                sb.Append(bytes[i].ToString("X").PadLeft(2, '0'));
                sb.Append(" ");

                if (i % _cl == _cl - 1)
                {
                    sb.Append(": ");
                    for (int j = i - (_cl - 1); j <= i; j++)
                        sb.Append(byteToPrintableChar(bytes[j]));
                    sb.Append(Environment.NewLine);
                }
            }

            if (bytes.Length % _cl != 0)
            {
                for (int i = 0; i < _cl - (bytes.Length % _cl); i++)
                    sb.Append("   ");

                sb.Append(": ");

                for (int j = bytes.Length - (bytes.Length % _cl); j < bytes.Length; j++)
                    sb.Append(byteToPrintableChar(bytes[j]));

                for (int i = 0; i < _cl - (bytes.Length % _cl); i++)
                    sb.Append(" ");

                sb.Append(Environment.NewLine);
            }

            return sb.ToString();
        }