Be.Windows.Forms.HexBox.ConvertHexToBytes C# (CSharp) Méthode

ConvertHexToBytes() private méthode

Converts the hex string to an byte array. The hex string must be separated by a space char ' '. If there is any invalid hex information in the string the result will be null.
private ConvertHexToBytes ( string hex ) : byte[]
hex string the hex string separated by ' '. For example: "0A 0B 0C"
Résultat byte[]
        byte[] ConvertHexToBytes(string hex)
        {
            if (string.IsNullOrEmpty(hex))
                return null;
            hex = hex.Trim();
            var hexArray = hex.Split(' ');
            var byteArray = new byte[hexArray.Length];

            for (int i = 0; i < hexArray.Length; i++)
            {
                var hexValue = hexArray[i];

                byte b;
                var isByte = ConvertHexToByte(hexValue, out b);
                if (!isByte)
                    return null;
                byteArray[i] = b;
            }

            return byteArray;
        }
HexBox