Updated: 27 August 2010
Use BIN2HEX to convert a binary number to a hexadecimal
Syntax
SELECT [wctEngineering].[wct].[BIN2HEX] (
<@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, BIN2HEX 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), BIN2HEX returns an error.
· If @Number is negative, BIN2HEX ignores places and returns a 10-character hexadecimal number.
· @Places is truncated to zero decimal places.
Examples
select wct.BIN2HEX('1000000000', NULL)
This produces the following result
------------------------------
FFFFFFFE00
(1 row(s) affected)
select wct.BIN2HEX('111111111', NULL)
This produces the following result
--------------------------------
1FF
(1 row(s) affected)
select wct.BIN2HEX('111111111', 10)
This produces the following result
---------------------------------
00000001FF
(1 row(s) affected)