Logo

BIN2OCT

Updated 2023-11-08 15:58:02.277000

Syntax

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

Description

Use the scalar function  BIN2OCT to convert a binary number to an octal.

Arguments

@Places

The number of characters to use. If @Places is NULL, BIN2OCT 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), BIN2OCT returns an error.

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

@Places is truncated to zero decimal places.

Examples

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

This produces the following result.

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

This produces the following result.

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"777"}]}
select wct.BIN2OCT('111111111', 10);

This produces the following result.

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