Core/CafeLib.Core/Support/ObjectId.cs
/// <summary>
/// Parses a hex string into its equivalent byte array.
/// </summary>
/// <param name="s">The hex string to parse.</param>
/// <returns>The byte equivalent of the hex string.</returns>
Parses a hex string into its equivalent byte array.
Parses a hex string into its equivalent byte array .
public static byte[] ParseHexString(string s)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }
            if ((s.Length & 1) != 0)
            {
                s = "0" + s; 
            }
            var bytes = new byte[s.Length / 2];
            for (var i = 0; i < bytes.Length; i++)
            {
                var hex = s.Substring(2 * i, 2);
                try
                {
                    var b = Convert.ToByte(hex, 16);
                    bytes[i] = b;
                }
                catch (FormatException e)
                {
                    throw new FormatException(
                        $"Invalid hex string {s}. Problem with substring {hex} starting at position {2 * i}",
                        e);
                }
            }
            return bytes;
        }
public static byte [ ] ParseHexString ( string s ) { if ( s == null ) { throw new ArgumentNullException ( nameof ( s ) ) ; } if ( ( s . Length & 1 ) != 0 ) { s = " " + s ; } var bytes = new byte [ s . Length / 2 ] ; for ( var i = 0 ; i < bytes . Length ; i ++ ) { var hex = s . Substring ( 2 * i , 2 ) ; try { var b = Convert . ToByte ( hex , 16 ) ; bytes [ i ] = b ; } catch ( FormatException e ) { throw new FormatException ( $" Invalid hex string  { s } . Problem with substring  { hex }  starting at position  { 2 * i } " , e ) ; } } return bytes ; }
Parses a hex string into its equivalent byte array.
Parses a hex string into its equivalent byte array .
// make length of s even
The byte equivalent of the hex string.
The byte equivalent of the hex string .
s
string
The hex string to parse.
The hex string to parse .