Пример #1
0
        public static string ByteArrayToString(this byte[] ba, StringType type = StringType.Hex)
        {
            if (!type.HasFlag(StringType.Hex))
            {
                return(Encoding.UTF8.GetString(ba));
            }

            var hex = new StringBuilder(ba.Length * 2 + 2);

            if (type.HasFlag(StringType.ZeroLowerX))
            {
                hex.Append("0x");
            }

            foreach (byte b in ba)
            {
                hex.AppendFormat("{0:x2}", b);
            }

            return(hex.ToString());
        }