Login     Register

        Contact Us     Search

XLeratorDB/engineering Online Documentation

SQL Server HEX2BIN function


 
Updated: 27 August 2010

Use HEX2BIN to convert a hexadecimal number to binary.
Syntax
SELECT [wctEngineering].[wct].[HEX2BIN] (
   <@Number, nvarchar(4000),>
 ,<@Places, float,>)
Arguments
@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
@Places
The number of characters to use. If @Places is NULL, HEX2BIN 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 FFFFFFFE00 or @Number is greater than 1FF, HEX2BIN returns an error.
·         If @Number is negative, HEX2BIN ignores places and returns a 10-character binary number.
·         If @Number is not a valid hexadecimal number, HEX2BIN returns an error.
·         @Places is truncated to zero decimal places.
Examples

select
wct.HEX2BIN('F',8)

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


slect
wct.HEX2BIN('B7',NULL)

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


select
wct.HEX2BIN('FFFFFFFFFF',NULL)

This produces the following result
--------------------------
1111111111
 

(1 row(s) affected)



Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service