全部博文(136)
分类: Oracle
2009-07-01 20:24:53
-- 6 = 0110
-- 7 = 0111
-- 13 =
1101 SQL> select bitand(6,13) from dual;BITAND(6,9)
-----------
4
SQL> select bitand(7,13) from dual;
BITAND(7,9)
-----------
5 |
SQL> CREATE OR REPLACE FUNCTION bitor (n1 NUMBER, n2 NUMBER) RETURN NUMBER
2 IS
3 n1_tmp NUMBER := trunc(n1);
4 n2_tmp NUMBER := trunc(n2);
5 BEGIN
6 RETURN n1_tmp + n2_tmp - bitand(n1_tmp, n2_tmp);
7 END;
8 /
Function created
-- 6 = 0110
-- 13 = 1101
SQL> select bitor(6,13) from dual;
BITOR(6,13)
-----------
15
-- 6 = 0110
-- 2 = 0010
SQL> select bitor(6,2) from dual;
BITOR(6,2)
-----------
6 |
SQL> CREATE OR REPLACE FUNCTION bitxor (n1 NUMBER, n2 NUMBER) RETURN NUMBER
2 IS
3 n1_tmp NUMBER := trunc(n1);
4 n2_tmp NUMBER := trunc(n2);
5 BEGIN
6 RETURN n1_tmp + n2_tmp - bitand(n1_tmp, n2_tmp)*2;
7 END;
8 /
Function created
-- 6 = 0110
-- 13 = 1101 SQL> select bitxor(6,13) from dual;
BITXOR(6,13)
------------
11
-- 6 = 0110
-- 2 = 0010 SQL> select bitxor(6,2) from dual;
BITXOR(6,2)
-----------
4 |