Login     Register

        Contact Us     Search

XLeratorDB/engineering Online Documentation

SQL Server BIN2OCT function


 
Updated: 27 August 2010

Use BIN2OCT to convert a binary number to an octal
Syntax
SELECT [wctEngineering].[wct].[BIN2OCT] (
   <@Number, nvarchar(4000),>
 ,<@Places, float,>)
Arguments
@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).
@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
Return Types
varchar(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
--------------------------------------
7777777000
 
(1 row(s) affected)


select
wct.BIN2OCT('111111111', NULL)

This produces the following result
----------------------------------------
777
 
(1 row(s) affected)


select
wct.BIN2OCT('111111111', 10)

This produces the following result
----------------------------------------
0000000777
 
(1 row(s) affected)


Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service