Logo

BIN2HEX

Updated 2023-11-08 15:56:23.100000

Syntax

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

Description

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

Arguments

@Places

The number of characters to use. If @Places is NULL, BIN2HEX 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 value at which to evaluate the function. The most significant bit of number is the sign bit. The remaining 9 bits are magnitude bits. Negative numbers are represented using two's-complement notation.@Number is an expression of type varchar or of a type that can be implicitly converted to varchar and must contain only zeros (0) or ones (1).

Return Type

nvarchar(4000)

Remarks

If @Number is not a valid binary number, or if @Number contains more than 10 characters (10 bits), BIN2HEX returns an error.

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

@Places is truncated to zero decimal places.

Examples

select wct.BIN2HEX('1000000000', NULL);

This produces the following result.

{"columns":[{"field":"column 1"}],"rows":[{"column 1":"FFFFFFFE00"}]}
select wct.BIN2HEX('111111111', NULL);

This produces the following result.

{"columns":[{"field":"column 1"}],"rows":[{"column 1":"1FF"}]}
select wct.BIN2HEX('111111111', 10);

This produces the following result.

{"columns":[{"field":"column 1"}],"rows":[{"column 1":"00000001FF"}]}