Logo

HEX2OCT

Updated 2023-11-08 16:13:45.920000

Syntax

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

Description

Use the scalar function HEX2OCT to convert a hexadecimal number to octal.

Arguments

@Places

The number of characters to use. If @Places is NULL, HEX2OCT 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 FFE0000000 or @Number is greater than 1FFFFFFF, HEX2OCT returns an error.

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

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

@Places is truncated to zero decimal places.

Examples

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

This produces the following result.

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

This produces the following result.

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

This produces the following result.

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