src/Shared/EntityFramework/Core/Common/EntitySql/AST/Literal.cs
// <summary>
// Converts hex string to byte array.
// </summary>
Converts hex string to byte array.
Converts hex string to byte array .
private static byte[] ConvertBinaryLiteralValue(string binaryLiteralValue)
        {
            DebugCheck.NotNull(binaryLiteralValue);
            if (String.IsNullOrEmpty(binaryLiteralValue))
            {
                return _emptyByteArray;
            }
            var startIndex = 0;
            var endIndex = binaryLiteralValue.Length - 1;
            Debug.Assert(startIndex <= endIndex, "startIndex <= endIndex");
            var binaryStringLen = endIndex - startIndex + 1;
            var byteArrayLen = binaryStringLen / 2;
            var hasOddBytes = 0 != (binaryStringLen % 2);
            if (hasOddBytes)
            {
                byteArrayLen++;
            }
            var binaryValue = new byte[byteArrayLen];
            var arrayIndex = 0;
            if (hasOddBytes)
            {
                binaryValue[arrayIndex++] = (byte)HexDigitToBinaryValue(binaryLiteralValue[startIndex++]);
            }
            while (startIndex < endIndex)
            {
                binaryValue[arrayIndex++] =
                    (byte)
                    ((HexDigitToBinaryValue(binaryLiteralValue[startIndex++]) << 4)
                     | HexDigitToBinaryValue(binaryLiteralValue[startIndex++]));
            }
            return binaryValue;
        }
private static byte [ ] ConvertBinaryLiteralValue ( string binaryLiteralValue ) { DebugCheck . NotNull ( binaryLiteralValue ) ; if ( String . IsNullOrEmpty ( binaryLiteralValue ) ) { return _emptyByteArray ; } var startIndex = 0 ; var endIndex = binaryLiteralValue . Length - 1 ; Debug . Assert ( startIndex <= endIndex , " " ) ; var binaryStringLen = endIndex - startIndex + 1 ; var byteArrayLen = binaryStringLen / 2 ; var hasOddBytes = 0 != ( binaryStringLen % 2 ) ; if ( hasOddBytes ) { byteArrayLen ++ ; } var binaryValue = new byte [ byteArrayLen ] ; var arrayIndex = 0 ; if ( hasOddBytes ) { binaryValue [ arrayIndex ++ ] = ( byte ) HexDigitToBinaryValue ( binaryLiteralValue [ startIndex ++ ] ) ; } while ( startIndex < endIndex ) { binaryValue [ arrayIndex ++ ] = ( byte ) ( ( HexDigitToBinaryValue ( binaryLiteralValue [ startIndex ++ ] ) << 4 ) | HexDigitToBinaryValue ( binaryLiteralValue [ startIndex ++ ] ) ) ; } return binaryValue ; }
Converts hex string to byte array.
Converts hex string to byte array .
binaryLiteralValue
string