Logo

HEX2BIN

Updated 2023-11-08 16:10:24.750000

Syntax

SELECT [westclintech].[wct].[HEX2BIN] (
  <@Number, nvarchar(4000),>
 ,<@Places, float,>)

Description

Use the scalar function HEX2BIN to convert a hexadecimal number to binary.

Arguments

@Places

The number of characters to use. If @Places is NULL, HEX2BIN uses the minimum number of characters necessary. @Places is useful for padding the return value with leading 0s (zeros). @Places is an expression of type float or of a type that can be implicitly converted to float.

@Number

is the hexadecimal number you want to convert. @Number cannot contain more than 10 characters. The most significant bit of @Number is the sign bit (40th bit from the right). The remaining 39 bits are magnitude bits. Negative numbers are represented using two's-complement notation. @Number is an expression of type float or of a type that can be implicitly converted to float.

Return Type

nvarchar(4000)

Remarks

If @Number is less than FFFFFFFE00 or @Number is greater than 1FF, HEX2BIN returns an error.

If @Number is negative, HEX2BIN ignores places and returns a 10-character binary number.

If @Number is not a valid hexadecimal number, HEX2BIN returns an error.

@Places is truncated to zero decimal places.

Examples

select wct.HEX2BIN('F', 8);

This produces the following result.

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"00001111"}]}
select wct.HEX2BIN('B7', NULL);

This produces the following result.

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"10110111"}]}
select wct.HEX2BIN('FFFFFFFFFF', NULL);

This produces the following result.

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"1111111111"}]}