OCT2BIN
Updated 2023-11-08 16:15:22.460000
Syntax
SELECT [westclintech].[wct].[OCT2BIN] (
<@Number, nvarchar(4000),>
,<@Places, float,>)
Description
Use the scalar function OCT2BIN to convert an octal number to binary.
Arguments
@Places
The number of characters to use. If @Places is NULL, OCT2BIN 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 octal number you want to convert. @Number cannot contain more than 10 characters. The most significant bit of @Number is the sign bit (30th bit from the right). The remaining 29 bits are magnitude bits. Negative numbers are represented using two's-complement notation. @Number is an expression of type nvarchar or of a type that can be implicitly converted to nvarchar.
Return Type
nvarchar(4000)
Remarks
If @Number is less than 7777777000 or @Number is greater than 777, OCT2BIN returns an error.
If @Number is negative, OCT2BIN ignores places and returns a 10-character binary number.
If @Number is not a valid octal number, OCT2BIN returns an error.
@Places is truncated to zero decimal places.
Examples
select wct.OCT2BIN(66, 8);
This produces the following result.
{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"00110110"}]}
select wct.OCT2BIN(766, 8);
This produces the following result.
{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"111110110"}]}
select wct.OCT2BIN(7777777000, NULL);
This produces the following result.
{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"1000000000"}]}