HEXTOINT Function [Data Type Conversion]

Returns the unsigned BIGINT equivalent of a hexadecimal string.

Syntax

HEXTOINThexadecimal-string )

Parameters

Parameters

Description

hexadecimal-string

The string to be converted to an integer. Input can be in the following forms, with either a lowercase or uppercase “x” in the prefix, or no prefix:

0xhex-string
0Xhex-string
hex-string

Returns

The HEXTOINT function returns the platform-independent SQL INTEGER equivalent of the hexadecimal string. The hexadecimal value represents a negative integer if the 8th digit from the right is one of the digits 8-9 and the uppercase or lowercase letters A-F and the previous leading digits are all uppercase or lowercase letter F. The following is not a valid use of HEXTOINT since the argument represents a positive integer value that cannot be represented as a signed 32-bit integer:

SELECT HEXTOINT( '0x0080000001' );

INT

Remarks

For invalid hexadecimal input, SAP Sybase IQ returns an error unless the CONVERSION_ERROR option is OFF. When CONVERSION_ERROR is OFF, invalid hexadecimal input returns NULL.

See CONVERSION_ERROR Option [TSQL] in Reference: Statements and Options.

The database option ASE_FUNCTION_BEHAVIOR specifies that output of SAP Sybase IQ functions, including INTTOHEX and HEXTOINT, is consistent with the output of Adaptive Server functions.

See ASE_FUNCTION_BEHAVIOR Option in Reference: Statements and Options.

When the ASE_FUNCTION_BEHAVIOR option is ON:
  • SAP Sybase IQ HEXTOINT assumes input is a hexadecimal string of 8 characters; if the length is less than 8 characters long, the string is left padded with zeros.

  • SAP Sybase IQ HEXTOINT accepts a maximum of 16 characters prefixed with 0x (a total of 18 characters); use caution, as a large input value can result in an integer value that overflows the 32-bit signed integer output size.

  • The data type of the output of the SAP Sybase IQ HEXTOINT function is assumed to be a 32-bit signed integer.

  • SAP Sybase IQ HEXTOINT accepts a 32-bit hexadecimal integer as a signed representation.

  • For more than 8 hexadecimal characters, SAP Sybase IQ HEXTOINT considers only relevant characters.

Standards and Compatibility

  • SQL—Vendor extension to ISO/ANSI SQL grammar.

  • Sybase—Compatible with Adaptive Server.

Example

The following statements return the value 420:

SELECT HEXTOINT ( '0x1A4' ) FROM iq_dummy
SELECT HEXTOINT ( '0X1A4' ) FROM iq_dummy
SELECT HEXTOINT ( '1A4' ) FROM iq_dummy
Related reference
BIGINTTOHEX Function [Data Type Conversion]
HEXTOBIGINT Function [Data Type Conversion]
INTTOHEX Function [Data Type Conversion]