Login     Register

        Contact Us     Search

XLeratorDB/engineering Online Documentation

SQL Server OCT2BIN function


 
Updated: 27 August 2010

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


select
wct.OCT2BIN(766,8)

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


select
wct.OCT2BIN(7777777000,NULL)

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


Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service