ImageMagick.HexColor.ParseHex C# (CSharp) Method

ParseHex() private static method

private static ParseHex ( string value, int offset, int length ) : Byte
value string
offset int
length int
return System.Byte
    private static QuantumType ParseHex(string value, int offset, int length)
    {
      QuantumType result = 0;
      QuantumType k = 1;

      int i = length - 1;
      while (i >= 0)
      {
        char c = value[offset + i];

        if (c >= '0' && c <= '9')
          result += (QuantumType)(k * (c - '0'));
        else if (c >= 'a' && c <= 'f')
          result += (QuantumType)(k * (c - 'a' + '\n'));
        else if (c >= 'A' && c <= 'F')
          result += (QuantumType)(k * (c - 'A' + '\n'));
        else
          throw new ArgumentException("Invalid character: " + c + ".", nameof(value));

        i--;
        k = (QuantumType)(k * 16);
      }

      return result;
    }