5>
6> CREATE FUNCTION dbo.bitwise_xor(
7> @arg1 varbinary(8),
8> @arg2 varbinary(8)
9> ) RETURNS varbinary(8)
10> AS
11> BEGIN
12> DECLARE
13> @result AS varbinary(8),
14> @numbytes AS int,
15> @curpos AS int
16> SET @result = 0x
17> SET @numbytes = DATALENGTH(@arg2)
18> SET @curpos = 1
19> WHILE @curpos <= @numbytes
20> BEGIN
21> SELECT
22> @result = @result + CAST(SUBSTRING(@arg1, @curpos, 1) ^
23> CAST(SUBSTRING(@arg2, @curpos,1)
24> AS tinyint)
25> AS binary(1))
26> SET @curpos = @curpos + 1
27> END
28> RETURN @result
29> END
30> GO
1> GRANT EXECUTE ON dbo.bitwise_xor TO public
2> GO
1>
2> SELECT dbo.bitwise_xor(0x00000001000000010000000100000001,
3> 0xffffffffffffffffffffffffffffffff)
4>
5> drop function dbo.bitwise_xor
6> GO
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
----------------------------------
0xFFFFFFFEFFFFFFFE
(1 rows affected)
1>
2>